chmod changes the permissions of a file or a directory. Only the owner of the file, or root, can do it.
chmoduwho: u g o a++ add, - remove, = setxwhich: r w xrun.shthe file
| Who | Means |
|---|---|
u | The owner (user) |
g | The group |
o | All other accounts |
a | All three |
Examples
| Line | Change |
|---|---|
chmod u+x run.sh | The owner can run it |
chmod g-w notes.txt | The group can no longer change it |
chmod o= pay.txt | All other accounts get nothing |
chmod g+rw,o-r rota.txt | Two changes, with a comma and no space |
The permissions that you do not name stay as they were.
text
learner@tidepool:~$ ls -l run.sh
-rw-r--r-- 1 learner learner 31 Oct 12 09:14 run.sh
learner@tidepool:~$ chmod u+x run.sh
learner@tidepool:~$ ls -l run.sh
-rwxr--r-- 1 learner learner 31 Oct 12 09:14 run.shNot your file
text
learner@tidepool:~$ chmod o= /srv/shop/rota.txt
chmod: changing permissions of '/srv/shop/rota.txt': Operation not permittedA full directory: -R
chmod -R changes a directory and everything under it, the same as cp -r and rm -r. Be careful: chmod -R a+x gives x to every file too.