new-mode describes the access permissions you want
after the change. There are two
ways to specify the mode: you can use either a numeric
mode or some symbols that describe the changes.
I generally prefer the numeric mode (because I'm strange, I
suppose). Anyway, to use
a numeric mode, decide what permissions you
want to have,
and give a command like:
chmod 644 report.txt
This gives read and write access to the owner of report.txt and read-only access to everyone else.
Most users prefer to use the symbolic mode to specify permissions. A symbolic chmod command looks like this:
chmod g-w report.txt
This means "take away write access for group members." The symbols used in mode specifications are shown in Table 22.1.
|Who:||u||User (owner) of the file.|
|a||All (i.e., user, group, and others).|
|What to do:||-||Take away this permission.|
|+||Add the indicated permission.|
|X||Give (or deny) execute permission to directories, or to files that have another "execute" bit set.|
|s||Set user or group ID (only valid with |
(Article 22.2 explains the "Who" and "Permissions" categories.) Here are a few example symbolic modes:
Set others access to read-only, regardless of what other bits are set.
Add read access for others.
Take away write access for group members and others.
Give everyone (user, group, and others) read-write (but not execute) access.
- add or delete certain permissions, but
leave the others untouched. The commands below show how permissions
are added and subtracted:
ls -l foo-rwx---x 1 mikel 0 Mar 30 11:02 foo %
chmod a+x foo%
ls -l foo-rwx-x-x 1 mikel 0 Mar 30 11:02 foo %
chmod o-x,g+r foo%
ls -l foo-rwxr-x-- 1 mikel 0 Mar 30 11:02 foo %
Note the last chmod command. It shows something we haven't mentioned before. With symbolic mode, you're allowed to combine two (or more) specifications, separated by commas. This command says "take away execute permission for others, and add read access for group members."
|chmod||The GNU version of chmod is on the CD-ROM.|
On occasion, I've wanted to change the permissions of a whole directory tree: all the files in a directory and all of its subdirectories. In this case, you want to use chmod -R (the R stands for recursive) or . You won't need this often, but when you do, it's a real lifesaver.