The more arcane method uses three octal digits to show what the permissions should be. The octal numbers are created by associating each triplet of the file's permissions with a three-digit binary number which is then converted into a single-digit octal number.
Let's stretch out a permission string so we can see what's going on:
So "rwxr-xr-x" can be thought of as three three-digit binary numbers with "r", "w", or "x" representing a "1", and "-" representing a "0". When you convert the three digit binary number to a one-digit octal number you get the following corresponcences:
|These two aren't real useful|
So to change a file's permission to be "rw-rw-r--", you'd read that as three sets of bits "110 110 100", and convert those into octal to get "664" which you would use as an argument to chmod like so:
% ls -lg foo -rwxr-xr-x 1 jeffy se 24576 May 9 16:13 foo % chmod 664 foo % ls -lg foo -rw-rw-r-- 1 jeffy se 24576 May 9 16:13 foo
The other method available in chmod is more symbolic and more flexible. You specify the permissions with an argument made up of three parts:
If the "who" portion is ommitted, the change is applied to all of user, group and other. It only makes sense to omit the permission portion with the "=" operator to set the permission to "---".
Here's a few examples:
% ls -lg foo [I'll leave out the other ls's to reduce clutter] -rw-rw-r-- 1 jeffy se 24576 May 9 16:13 foo % chmod +x foo -rwxrwxr-x 1 jeffy se 24576 May 9 16:13 foo % chmod go-rx foo -rwx-w---- 1 jeffy se 24576 May 9 16:13 foo % chmod g-w foo -rwx------ 1 jeffy se 24576 May 9 16:13 foo % chmod o=rx foo -rwx---r-x 1 jeffy se 24576 May 9 16:13 foo % chmod g+rx,u-w foo -r-xr-xr-x 1 jeffy se 24576 May 9 16:13 foo
As in that last chmod, you can do multiple symbolic changes by separating them with a comma.
Of course there are other things you can do with chmod, like setting executables up to be setuid, and setting the sticky bit, but these are things you do seldom enough that it doesn't make sense to remember them. RTFM when you want to do it.
Up to the TTTT index
Tuesday Tiny Techie Tips are all © Copyright 1996-1997 by Jeff Youngstrom. Please ask permission before reproducing any of this material.