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 myfile

Using chmod, we can take away the read permissions for the group (g) and the other users (o):

chmod g-r,o-r myfilels -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 myfilels -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.

File permission bits explained
Figure 2-2. File permission bits explained
Numeric format

Each triplet rwx can 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 (meaning r--), read and write together would be ...

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.