Quiz
Warm-up from lesson 2-3: in `ls -l` output, what appears at the very start of each line (like -rw-r--r--)?
Reading -rw-r--r--
You will meet permissions the hard way soon: a script that refuses to run, a Permission denied on a file you can see, ssh rejecting your key because other users could read it. Knowing how to read the permission string turns each of those from a mystery into a ten-second fix.
Linux is multi-user — several accounts share one machine — so every file records who may do what. Three actions, three audiences:
- Actions: read, write, execute (run it as a program, or enter it if it's a directory)
- Audiences: the file's user (owner), its group, and others (everyone else)
The 10-character string packs all of that:
| position | meaning |
|---|---|
| 1 | type: - file, d directory |
| 2-4 | owner's r w x |
| 5-7 | group's r w x |
| 8-10 | others' r w x |
So -rw-r--r-- means: regular file, owner can read+write, group can read, others can read. A dash means "not allowed".
Changing permissions: chmod
chmod (change mode) speaks two dialects:
Numeric: one digit per audience, adding r=4, w=2, x=1.
chmod 755 script.sh # rwx r-x r-x chmod 600 secret.txt # rw- --- ---
Symbolic: who, then + or -, then what.
chmod u+x script.sh # give the owner execute chmod go-r notes.txt # remove read from group and others
The one you'll type most in your career is chmod +x script.sh: make a script executable. That's the doorway to unit 8.
Code exercise · bash
Run it. A fresh file starts as rw-r--r--, then chmod 755 turns on execute. The `cut -c1-10` just trims each ls -l line to its first 10 characters, the permission string. (umask 022 pins the default permissions so the output is predictable.)
Quiz
What does chmod 600 diary.txt allow?
Code exercise · bash
Your turn. Create `secret.txt`, lock it down so ONLY the owner can read and write it (one numeric chmod), and show the permission string. Expected output: ``` -rw------- ```