next up previous contents
Next: Exercises Up: Permissions/File Access Modes Previous: Permissions/File Access Modes   Contents

chmod: Change Mode (Permissions)

The chmod command allows a user to change the permissions of a file/directory. To use chmod, the user must be the owner of the file.

The syntax of the command is:

chmod [-R] mode filename(s)
-R is an option.
-R
(Recursively) will cause all files and directories within (underneath) the file/directory whose permissions are being changed to take those permissions.

mode may be specified as three octal values (one for each of the three sets of permissions): if any of the permission bits r,w, or x is set, the corresponding permission is enabled: give it a 1. If not, give it a 0. Then, for each of the three permission groups, interpret the three binary numbers as an octal number.

Another way to explain it is to give different weighing factors to the different permissions: 4 to ``r", 2 to ``w", and 1 to ``x". If the permission is set, add the weighing factor. Otherwise do not add anything to the group value.

Using the above example of the file phone.numbers, which had the rwxrwxr- permissions, it would translate to 111 111 100, or 774, or 4+2+1 4+2+1 4+0+0:

rwx rwx r-
111 111 100
7 7 4
If write permission for world (sometimes called others) is added, mode is changed to 776 (or 111 111 110, or 4+2+1 4+2+1 4+2+0).

mode may also be specified symbolically as +r which would add read permissions to everyone, or as -w which would take away write permissions from everyone (all groups).

filename(s) may be one or more filenames, and/or one or more directories, separated by blank spaces.

For example, to change the permissions on file phone.numbers, from rwxrwxr- to rwxrwxrw-, the command

chmod 776 phone.numbers
or
chmod +w phone.numbers
or (because we are changing it only in the others group)
chmod go+w phone.numbers
which means ``group others add write", could be used.

The general syntax, using the conventional method is

chmod [ugo]+$\vert$-[rwx] filename(s)
Where
u
: permission for user/owner.
g
: permission for group.
o
: permission for others.
r
: read permission.
w
: write permission.
x
: execute permission.

Any combination of ugo, rwx may be used. If none is used, then all three are assumed. One exception: if chmod - is used, the result depends on the value of umask (umask sets the default permissions on files; usually 022 at NRC - see man page for details).

It is also acceptable to put a combination of ``[ugo]+$\vert$-[rwx]", as long as they are separated by a comma (,), as in

chmod ug+x,o-x filename
.

Typing the command

chmod -help (linux)
or
chmod (generic UNIX)
by itself will display the usage of the command.

Refer to the UNIX manual of your machine for more options on the command.


next up previous contents
Next: Exercises Up: Permissions/File Access Modes Previous: Permissions/File Access Modes   Contents
Claude Cantin 2010-10-24