Changing the group association of files and directories with chgrp

Suppose you have a file called black that is currently being used by the pot group and you want to change the file's permissions so that it can be accessed by the kettle group. To do this, you'll need to change which group the file is associated with—in this case, change the association from the pot group to the kettle group. You can change which group a file or directory is associated with using chgrp, as shown in Code Listing 5.5.

To change group association with chgrp:

1.
ls -l

To begin, type ls -l at the shell prompt to verify the file's name and the group it's associated with, as in Code Listing 5.5. Remember that the second column in the middle of the listing, immediately before the file sizes, lists the group membership.

2.
chgrp kettle black

Type chgrp followed by the name of the new group you want to the file to be associated with and the file name. Here, the chgrp command changes the group association for the file called black to the kettle group.

You can also change the association of a directory and all of the contents using chgrp -R, like this: chgrp -R kettle blackdirectory.

Code Listing 5.5. Pots and kettles can both be black, but only one at a time.
[ejr@hobbes permissions]$ ls -l
total 178
-rw-rw-r--  1 ejr   pot     24850 Jul 24 14:59 black
-rw-rw-r--  1 ejr   ejr    128889 Jul 24 14:33 sage.sayings
-rw-rw-r--  1 ejr   ejr     23890 Jul 24 14:33 sayings
[ejr@hobbes permissions]$ chgrp kettle black
[ejr@hobbes permissions]$ ls -l
total 178
-rw-rw-r--  1 ejr   kettle   24850 Jul 24 14:59 black
-rw-rw-r--  1 ejr   ejr    128889 Jul 24 14:33 sage.sayings
-rw-rw-r--  1 ejr   ejr     23890 Jul 24 14:33 sayings

Tip

If you try to change group ownership and get an error message like "Not owner" or something similarly obscure, your userid doesn't have the necessary authority to make the change. You'll have to ask your system administrator for help.


Tip

Only change group association if you have a specific need to do so; you don't want to make your files available to other people unnecessarily. Unless you are the system administrator, you won't be able to control exactly who belongs to the group to which you've given access to your files.


Tip

If you change the group association of a specific directory, you also need to check permissions for the directory containing it. Users will not be able to change into the specific directory (regardless of their group membership) unless they also have read and execute permission for the directory containing it.


Tip

Just as with the cp and mv commands, covered in Chapter 1, you can use a -R flag with chgrp to recursively apply changes to a directory and all of the subdirectories and files in it. For example, to change the group association of the LatestProject directory and all its contents to the project group, use chgrp -R project LatestProject from the directory above LatestProject.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.134