Name
chmod — stdin stdout - file -- opt --help --version
Synopsis
chmod [options]permissions files
The chmod (change mode)
command protects files and directories from unauthorized access in the
filesystem by setting access permissions. We described these
permissions—read (r), write
(w), and execute (x)—in File Protections.
These permissions are described as a string of nine characters
(rwxrwxrwx) consisting of three
triplets: the first for the user owning the file, the second for group
ownership, and the third for other users.
For example, here we have a file myfile that is readable and writable by its owner, readable by its group, and readable by others:
➜ ls -l myfile
-rw-r--r-- 1 smith staff 4 Apr 26 22:22 myfileUsing chmod, we can take away
the read permissions for the group (g) and the other users (o):
➜chmod g-r,o-r myfile➜ls -l myfile-rw------- 1 smith staff 4 Apr 26 22:23 myfile
Now we make the file read-only for all users (a):
➜chmod a=r myfile➜ls -l myfile-r--r--r-- 1 smith staff 4 Apr 26 22:24 myfile
chmod understands permissions in two formats, one
numeric, and one symbolic, as depicted in Figure 2-2.

- Numeric format
Each triplet
rwxcan be represented by a number. Imagine that the digit 1 means a permission is present and zero means absent. So read-only permission would be 100 (meaningr--), read and write together would be ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access