50.5. Using chmod to Change File Permission
% chmod new-mode file(s)
The 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). To use a numeric mode, decide what permissions you want to have, express them as an octal number (Section 1.17, Section 50.2), and give a command like this one:
% chmod 644 report.txt
This gives read and write access to the owner of report.txt and read-only access to everyone else.
% chmod g-w report.txt
This means "take away write access for group members." The symbols used in mode specifications are shown in Table 50-1.
Table 50-1. chmod symbolic modes
(Section 50.2 explains the "Who" and "Permissions" categories.) Here are a few example symbolic modes:
% 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."
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 find -exec (Section 9.9, Section 50.6). You won't need this often, but when you do, it's a real lifesaver.
Copyright © 2003 O'Reilly & Associates. All rights reserved.