chmod — stdin stdout - file -- opt --help --version
chmod (change mode)
command protects files and directories from unauthorized access in the
filesystem by setting access permissions. We described these
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
chmod, we can take away
the read permissions for the group (
g) and the other users (
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 (
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.
Figure 2-2. File permission bits explained
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 ...