[Next] [Previous] [Up] [Top] [Contents]

3.7 File Maintenance Commands

3.7.5 chmod - change file permissions

The command to change permissions on an item (file, directory, etc) is chmod (change mode). The syntax involves using the command with three digits (representing the user (owner, u) permissions, the group (g) permissions, and other (o) user's permissions) followed by the argument (which may be a file name or list of files and directories). Or by using symbolic representation for the permissions and who they apply to.

Each of the permission types is represented by either a numeric equivalent:

read=4, write=2, execute=1

or a single letter:

read=r, write=w, execute=x

A permission of 4 or r would specify read permissions. If the permissions desired are read and write, the 4 (representing read) and the 2 (representing write) are added together to make a permission of 6. Therefore, a permission setting of 6 would allow read and write permissions.

Alternatively, you could use symbolic notation which uses the one letter representation for who and for the permissions and an operator, where the operator can be:

+ add permissions

- remove permissions

= set permissions

So to set read and write for the owner we could use "u=rw" in symbolic notation.

Syntax

chmod nnn [argument list] numeric mode

chmod [who]op[perm] [argument list] symbolic mode

where nnn are the three numbers representing user, group, and other permissions, who is any of u, g, o, or a (all) and perm is any of r, w, x. In symbolic notation you can separate permission specifications by commas, as shown in the example below.

Common Options

-f force (no error message is generated if the change is unsuccessful)

-R recursively descend through the directory structure and change the modes

Examples

If the permission desired for file1 is user: read, write, execute, group: read, execute, other: read, execute, the command to use would be

chmod 755 file1 or chmod u=rwx,go=rx file1

Reminder: When giving permissions to group and other to use a file, it is necessary to allow at least execute permission to the directories for the path in which the file is located. The easiest way to do this is to be in the directory for which permissions need to be granted:

chmod 711 . or chmod u=rw,+x . or chmod u=rwx,go=x .

where the dot (.) indicates this directory.


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]