Chapter 7: Ownerships & Permissions

The following was removed from Chapter 7: “Ownerships & Permissions”.

Keep Track of Changes Made to a File’s Group with chgrp

chgrp -v
chgrp -c

You’ve probably noticed that chgrp, like all well-behaved Linux applications, only gives you feedback if there’s a problem. If a program works and does its job correctly, it doesn’t bother you with “Hey! I did it, and it worked!” Instead, Linux command-line applications are only noisy when an issue needs to be resolved.

If you want to know what chgrp is doing while it’s doing it, first try the -v (or --verbose) option. This tells you, every step of the way, just what tasks chgrp performs.

$ ls -lF
drwxr-xr-x  4 scott scott   192 2005-10-21 17:59 by_pool/
-rw-r--r--  1 scott scott   73K 2005-10-20 12:12 libby_arrowrock.jpg
-rw-r--r--  1 scott family  18K 2005-04-19 00:57 libby.jpg
-rw-r--r--  1 scott scott  194K 2005-04-19 00:57 libby_on_couch.jpg
drwxr-xr-x  2 scott scott   208 2005-10-21 13:30 on_floor/
$ chgrp -v family *
changed group of 'by_pool' to family
changed group of 'libby_arrowrock.jpg' to family
group of 'libby.jpg' retained as family
changed group of 'libby_on_couch.jpg' to family
changed group of 'on_floor' to family
$ ls -lF
drwxr-xr-x  4 scott family  192 2005-10-21 17:59 by_pool/
-rw-r--r--  1 scott family  73K 2005-10-20 12:12 libby_arrowrock.jpg
-rw-r--r--  1 scott family  18K 2005-04-19 00:57 libby.jpg
-rw-r--r--  1 scott family 194K 2005-04-19 00:57 libby_on_couch.jpg
drwxr-xr-x  2 scott family  208 2005-10-21 13:30 on_floor/

Notice what happened in this example. The libby.jpg file was already a member of the family group, but -v went ahead and reported on it anyway, making sure that you knew that libby.jpg’s group was kept as family. If you’re changing groups, you probably don’t need to know about items that already belong to the new group. In cases like that, you want to use the -c (or --changes) option, which (unsurprisingly) only reports changes made.

$ ls -lF
drwxr-xr-x  4 scott scott   192 2005-10-21 17:59 by_pool/
-rw-r--r--  1 scott scott   73K 2005-10-20 12:12 libby_arrowrock.jpg
-rw-r--r--  1 scott family  18K 2005-04-19 00:57 libby.jpg
-rw-r--r--  1 scott scott  194K 2005-04-19 00:57 libby_on_couch.jpg
drwxr-xr-x  2 scott scott   208 2005-10-21 13:30 on_floor/
$ chgrp -c family *
changed group of 'by_pool' to family
changed group of 'libby_arrowrock.jpg' to family
changed group of 'libby_on_couch.jpg' to family
changed group of 'on_floor' to family
$ ls -lF
drwxr-xr-x  4 scott family  192 2005-10-21 17:59 by_pool/
-rw-r--r--  1 scott family  73K 2005-10-20 12:12 libby_arrowrock.jpg
-rw-r--r--  1 scott family  18K 2005-04-19 00:57 libby.jpg
-rw-r--r--  1 scott family 194K 2005-04-19 00:57 libby_on_couch.jpg
drwxr-xr-x  2 scott family  208 2005-10-21 13:30 on_floor/

This time, nothing was reported to you about libby.jpg because it was already in the family group. So if you want a full report, even for files that won’t be changed, use -v; for a more concise listing, use -c.

WebSanity Top Secret