chmod

What is chmod?

In Linux, and other UNIX based operating system, who can do what to a file or directory is controlled through sets of access permissions and the special mode flags of file system objects.

Collectively these were originally called its modes, and the name "chmod" was chosen as an abbreviation of "change mode".

There are three sets of permissions. One set for the owner of the file, another set for the members of the file's group, and a final set for everyone else.

The permissions control the actions that can be performed on the file or directory. They either permit, or prevent, a file from being read, modified or, if it is a script or program (such as a Perl script), executed.

For a directory, the permissions govern who can move into the directory and who can create, or modify files within the directory.

Permissions may be indicated by either a nine character string, or a three digit number.

For a 9 character permission string:

  • The first three characters show the permissions for the user who owns the file (user permissions).
  • The middle three characters show the permissions for members of the file's group (group permissions).
  • The last three characters show the permissions for anyone not in the first two categories (other permissions).

The characters are indicators for the presence or absence of one of the permissions. They are either a dash (-) or a letter. If the character is a dash, it means that permission is not granted. If the character is an r, w, or an x, that permission has been granted.

The letters represent:

  • r: Read permissions. The file can be opened, and its content viewed.
  • w: Write permissions. The file can be edited, modified, and deleted.
  • x: Execute permissions. If the file is a script or a program, it can be run (executed).

For example, a permission string of "---" indicates that no permissions have been granted. A permissions string of "rwx" means full permissions have been granted, as the read (r), write (w), and execute (x) flags are all present.

For a 3 digit number:

  • The first digit shows the permissions for the user who owns the file (user permissions).
  • The second digit shows the permissions for members of the file's group (group permissions).
  • The third digit shows the permissions for anyone not in the first two categories (other permissions).

Each digit can be in the range 0 - 7, and is a decimal representation of a binary number.

  • 0 (000) indicates that a permissions has not been set.
  • 1 (001) indicates the Execute permission has been granted.
  • 2 (010) indicates the Write permission has been granted.
  • 3 (011) indicates that both the Execute (1) and Write (2) permissions have been granted.
  • 4 (100) indicates the Read permission has been granted.
  • 5 (101) indicates that both the Read (4) and Execute (1) permissions have been granted.
  • 6 (110) indicates that both the Read (4) and Write (2) permissions have been granted.
  • 7 (111) indicates that the Read (4), Write (2), and Execute (1) permissions have all been granted.

Examples of common chmod file permissions:

  • rw------- (600): Owner has read/write permissions. Group and Others have no permissions.
  • rw-r--r-- (644): Owner has read/write permissions. Group and Others have read-only permissions.
  • rwxr-xr-x (755): Owner has read, write, and execute permissions. Group and Others have read and execute permissions.

These last permissions, rwxr-xr-x (755), are required to be set on Perl (.pl) files in order for them to run (be executable) on your web server.


Related Terms


Glossary »