Change the Owner of Files and Directories


chown

Changing a file's group is important, but it's far more likely that you'll change owners. To change groups, use chgrp; to change owners, use chown.

$ ls -l -rw-r--r-- 1 scott scott ... libby_arrowrock.jpg -rw-r--r-- 1 scott family ... libby.jpg -rw-r--r-- 1 scott scott ... libby_on_couch.jpg $ chown denise libby.jpg $ ls -l -rw-r--r-- 1 scott scott ... libby_arrowrock.jpg -rw-r--r-- 1 denise family ... libby.jpg -rw-r--r-- 1 scott scott ... libby_on_couch.jpg 


Some of the points previously made about chgrp in "Change the Group Owning Files and Directories" apply to chown as well. The chgrp command uses either a user's name or her numeric ID. The numeric ID for users can be seen by running cat /etc/passwd, which gives you something like this:

bind:x:110:118::/var/cache/bind:/bin/false scott:x:1001:1001:Scott,,,:/home/scott:/bin/bash ntop:x:120:120::/var/lib/ntop:/bin/false 


The first number you see is the numeric ID for that user (the second number is the numeric ID for the main group associated with the user).

Also, you can only change the owner of a file if you are the current owner (or root, of course). That shouldn't surprise you, but it's good to remember nonetheless.

Caution

If you use chown -R scott *, you do not change any of the dot files in the directory. However, chown -R scott .* should not be used. It changes all the dot files in the current directory, but .* also matches .., so all the files in the parent directory are also changed, which is probably not what you want.




Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net