Main Page | See live article | Alphabetical index

Chmod

chmod (abbreviated from change mode) is a shell command in Unix-like environments.

When executed, the command can change file system modes of files and directories. The modes include permissions and special modes.

Table of contents
1 History
2 Sample use
3 Usage
4 External links

History

A chmod command appeared in AT&T UNIX version 1.

Sample use

Example:

chmod +rw file.txt

The chmod command will change the permissions of the file file.txt to read and write for all.

chmod -R u+w go-w docs/

The chmod command will change the permissions of the directory docs and all its contents to add write access for the user, and deny write access for everybody else.

Usage

The chmod command options are specified like this:

chmod switches modes files

Switches

chmod has a number of command line options, or "switches", that can modify the output. Some of these options are

Modes

There are permissions and special modes. The permissions are:

r - read permission;
w - write permission;
x - execute permission;

For each file is specified which permissions apply to the owner of the file, users in the group of the file, or all other users.

The modes can be specified in two ways, with characters or octal numbers. For characters, there are modification operators such that + adds the mode, = sets the mode, and - removes the mode setting.

Specified as:
+r read is added for all;
u=rw go= read and write is set for the owner, all permissions are cleared for the group and others;
-x execute permission is removed for all;

In octal mode, four numbers are specified and used to set the mode of a file. For owner, group and other the value of each setting is added and the modes are concatenated. The modes are given the values r 4; w 2; x 1.

Specified as:
0755 - Equivalent to u=rwx go=rx. The 0 specifies no special modes.

External links