Change the Owner and Group of Files and Directories


chown owner:group

You've seen that you can use chgrp to change groups and chown to change owners, but it's possible to use chown to kill two birds with one stone. After chown, specify the user and then the group, separated by a colon, and finally the file or directory (this is one reason why you should avoid using colons in user or group names).

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


You can even use chown to change only a group by leaving off the user in front of the colon.

$ ls -l -rw-r--r-- 1 scott scott ... libby.jpg $ chown :family libby.jpg $ ls -l-rw-r--r-- 1 scott family ... libby.jpg 


Tip

What if a user or group does have a colon in its name? Just type the backslash in front of that colon, which "escapes" the character and tells the system that it's just a colon, and not a separator between a user and group name:

$ chown denise:family\:parents libby.jpg 


This works, but it's better to disallow colons in user and group names in the first place.


Because chown does everything chgrp does, there's very little reason to use chgrp, unless you feel like it.

Note

When you separate the user and group, you can actually use either a . or : character. New recommendations are to stick with the :, however, because the . is deprecated.




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