I was recently asked by a colleague to use chmod
with letters instead of numbers. Apart from the obvious readability advantage is there any particular reason to use letters over numbers ?
Chmod – Chmod by Letters vs Numbers
chmod
chmod
I was recently asked by a colleague to use chmod
with letters instead of numbers. Apart from the obvious readability advantage is there any particular reason to use letters over numbers ?
Best Answer
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:
The
references
consists of a combination of the lettersugoa
, which specify which user's access to thefile
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 thereferences
component is omitted, it defaults to all users, but only permissions allowed by theumask
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, exceptsetuid
andsetgid
bits set for directories, unless explicitly specified.The
mode
consists of a combination of the lettersrwxXst
, 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
orsetgid
(depending on the specified references) (s
) and restricted deletion flag or sticky bit (t
). Alternatively, themode
can consist of one of the lettersugo
, in which case case themode
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
is0764/-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
:chmod 2764 file
chmod g+s file