Messing with Things: chmod
Permissions for files and directories can be changed using the chmod command, which allows the individual r/w/x permissions to be set/changed for the owner, group, and other users.
chmod has the following syntax:
chmod <permissions> <name>
chmod has two ways to represent the permissions for owner, group, and other: numeric and alphabetic. The numeric way works on the octal (base 8) values of the changes, and most people (except for UNIX wizards) will never use it.
Alphabetic is far more descriptive. The syntax is as follows:
chmod [u g o a][+ - =][r w x X] file
u = user (owner), g = group, o = other, a = all (short for ugo). Any combination of ugo can be specified (u, ug, ugo, uo, go, etc.). a is default if nothing is specified.
+ = add permission, - = remove permission, = only specified permission will be set (replacing existing permissions). Only one of these can be used.
r = read, w = write, x = execute/access, X = execute only if the file is a directory or already has execute permission for some user. Any combination can be used.
Here are some specific examples.
chmod u+x file: Adds (+) x permission for the owner only (rw-rw-rw- becomes rwxrw-rw-).
chmod u-w file: Removes (-) w permission for the owner only (rwxr-xrwx becomes r-xr-xrwx).
chmod g+w file: Adds w permission to group (rwx---rwx becomes rwx-w-rwx).
chmod o=x file: Sets x permission only to other (rwxrwxrw- becomes rwxrwx--x).
chmod a+rx file: Sets r and x permission for owner, group, and other (--------- becomes r-xr-xr-x).
You can also set different permissions for owner, group, and other in the same command:
chmod u+x,g-x,o+r file: Adds x permission to owner, removes x permission for group, and adds r permission to other (rw-rwx--- becomes rwxrw-r--).