Changing Permissions
Chmod changes the permissions of a file. It takes a mode, and the mode spells out the new letters.
An octal mode
600 gives read and write to the owner alone.
$ cd ~/practice
$ chmod 600 projects/report.txt
$ ls -l projects/report.txt
$ chmod 660 projects/report.txtA symbolic mode
U+x adds execute for the owner.
$ cd ~/practice
$ chmod u+x projects/report.txt
$ ls -l projects/report.txt
$ chmod 660 projects/report.txtTake a letter away
G-w takes write away from the group.
$ cd ~/practice
$ chmod g-w projects/report.txt
$ ls -l projects/report.txt
$ chmod 660 projects/report.txtExample
$ cd ~/practice
$ chmod 600 projects/report.txt
$ ls -l projects/report.txt
$ chmod 644 projects/report.txt
$ ls -l projects/report.txt
$ chmod 660 projects/report.txtKey points
- Use chmod to change the permissions of a file.
- A mode is a short code for the new letters.
- An octal mode uses three digits.
- Octal is a count in eights.
- Each octal digit stands for one set of three letters.
- Read is worth 4, write is worth 2, and execute is worth 1.
- A symbolic mode is written with letters, like u+x.
- U means the owner, g means the group, and o means everyone else.
- A plus sign adds a letter, and a minus sign takes one away.
- Chmod prints nothing when it works.
- Chmod rewrites the letters, and ls -l shows the new letters.
In this example, chmod 600 gives read and write to the owner alone. Ls -l shows -rw-------. Then chmod 644 adds read for the group and for everyone else. The last line puts the letters back to -rw-rw----.
Note
Chmod changes the letters, not the owner or the group.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command gives the owner read and write, and no one else anything?