LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-01-2007, 11:32 AM   #1
munna_dude
Member
 
Registered: Dec 2006
Posts: 362

Rep: Reputation: 30
replace a file in user level


hi all
how to replace a file in user level..
i tried this
Code:
cp -r /usr/lib/munna.txt /usr/lib/
saying the error permission denied..
is there any way..

please help me to replace a file in user level (not from root)

thank you in advance
 
Old 09-01-2007, 11:57 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
What do you mean by "replace"? for example: "cp" means copy---ie make a new file that is the same as the original, but in a new location. it probably failed because you don't have write permission to that directory.

Also:
The syntax of your command says "copy the file /usr/lib/munna.txt into /usr/lib" This will attempt to make the copy in the same location as the original, and bash will complain.

more also:
the -r option (recursive) has no meaning with a file. It is used when copying directories.
 
Old 09-01-2007, 12:03 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Do exactly what you did (with the proviso of pixellany's comments). The permission levels on the target file/directory must allow the user to perform the specified action. In your example case, the user performing the copy must have write permission in /usr/lib. Normally, write permission in that directory is limited to user 'root'. If you are are really, really sure you want to change the permissions, you may. I suggest you do it this way:
create a group, say 'admin', and make that group the group owner of the /usr/lib (or other, as appropriate) directory. Add write permissions to the group owner on the target directory. Add the appropriate small number of users to the 'admin' group.

Better still, use sudo. You will need to scrutinize the manpage for sudo to understand how to use visudo to configure the sudo config file. The payoff is that you can have more specific controls and limits regarding who is permitted to do what, and you may get a record of special actions by sudoers in syslog logs.

--- rod.

Last edited by theNbomr; 09-01-2007 at 12:04 PM.
 
Old 09-01-2007, 12:08 PM   #4
munna_dude
Member
 
Registered: Dec 2006
Posts: 362

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by pixellany View Post
What do you mean by "replace"? for example: "cp" means copy---ie make a new file that is the same as the original, but in a new location. it probably failed because you don't have write permission to that directory.

Also:
The syntax of your command says "copy the file /usr/lib/munna.txt into /usr/lib" This will attempt to make the copy in the same location as the original, and bash will complain.

more also:
the -r option (recursive) has no meaning with a file. It is used when copying directories.

sorry my question is wrong
Code:
cp -f /usr/lib/munna/munna.txt /usr/lib/
already there is a file munna.txt in /usr/lib
while running my script the file must be copy or overwrite in /usr/lib

please tell me if there is an other way..

thank you in advance
 
Old 09-01-2007, 12:14 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Again, you have to have write permissions to that folder (directory). If running from a script, then the permissions much be appropriate for the user who runs the script.
 
Old 09-01-2007, 12:44 PM   #6
munna_dude
Member
 
Registered: Dec 2006
Posts: 362

Original Poster
Rep: Reputation: 30
is there any waway to give the permission to that folder
 
Old 09-01-2007, 03:54 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Permissions are assigned to owner, group and others. Depending on who has access to your machine, you would choose the level of security. There is a GUI tool to set permissions, but I know it only from the command line. If the stuff below looks overwhelming, then start by finding the tool in your menus.

First, to see what the current permissions are:
cd /
ls -l
..........You will see a line for every top-level directory. Here is my entry for /usr:
drwxr-xr-x 12 root root 4096 Apr 17 17:57 usr/
Translation: The /usr directory is owned by root and assigned to the root group. The owner has full permissions (rwx), and the group and all other users have read + execute permissions (r-x)
With a directory, you need execute permission to open it, and you need write permission to change anything (including adding a file). Thus, if I am a regular user, I can enter this directory and browse, but I cannot change anything.

Here is one example of how to set permissions:
Suppose I want to create a file in /usr/share. Most things in /usr have the permissions shown above, so first, I will give "other users" write permission to /usr/share:
su (to take on root powers)
chmod o+w /usr/share
su username .....go back to my regular username
cd /usr/share
touch testfile
....creates an empty file "testfile"
As a normal user, I can now create a file in /usr/share (even though I still do not have write privileges to /usr---only /usr/share)

Here's one of many articles on file permissions---found with a Google search:
http://www.comptechdoc.org/os/linux/..._ugfilesp.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
replace a file in user level munna_dude Programming 1 09-02-2007 06:01 AM
emacs in run level 3 then switch to X (level 7) then back to level 3 dsoliver Slackware 3 09-01-2006 03:31 AM
scanner under user level ohcarol Linux - Hardware 1 11-29-2005 03:58 PM
user level fork() is05 Linux - Newbie 1 07-29-2005 10:09 PM
code in user level ramu_ak Linux - Networking 0 08-21-2003 01:52 AM


All times are GMT -5. The time now is 04:07 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration