Chmod by Letters Vs Numbers

The chmod symbolic notation is more fine-grained compared to the octal notation, allowing the modification of specific mode bits while leaving other mode bits untouched.

The symbolic notation consists of three components:

chmod [references][operator][modes] file

The references consists of a combination of the letters ugoa, which specify which user's access to the file will be modified: the user who owns it (u), other users in the file's group (g), other users not in the file's group (o), or all users (a). If the references component is omitted, it defaults to all users, but only permissions allowed by the umask are modified.

The + operator causes the specified file mode bits to be added to the existing file mode bits of each file; - causes them to be removed; and = causes them to be added and unspecified bits to be removed, except setuid and setgid bits set for directories, unless explicitly specified.

The mode consists of a combination of the letters rwxXst, which correspond to the read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X), setuid or setgid (depending on the specified references) (s) and restricted deletion flag or sticky bit (t). Alternatively, the mode can consist of one of the letters ugo, in which case case the mode corresponds to the permissions currently granted to the owner (u), member's of the file's group (g) or permssions of users in neither of the preceding categories (o).

Examples

Assuming the permission set for file is 0764/-rwxrw-r--

Remove permission from other users not in file's group:

  • Octal: chmod 760 file

    Note how the existing permissions left unchanged must be repeated when using the octal notation.

  • Symbolic: chmod o-rwx file

    With symbolic notation, the existing file permissions do not matter.

Set setuid:

  • Octal: chmod 4764 file

  • Symbolic: chmod u+s file

Set setgid:

  • Octal: chmod 2764 file
  • Symbolic chmod g+s file

Tags:

Chmod