A directory has the same three letters, but they mean different actions. A directory is a list of file names, and its permissions apply to that list.
A file's mode alone does not decide whether you can open it: the directory the file lies in has its say first.
/srv/permissions-lab holds a directory archive with the permission string drw-------: you, the owner, get rw-, with no x. Inside is note.txt, which everyone may read.
A directory without passage
You are in /srv/permissions-lab. Look at the line for the archive directory, its list of names, and try to read archive/note.txt.
First, predict
You have rw- on archive, and note.txt can be read by everyone. What will cat archive/note.txt print?
Now start the exercise, run the command and compare your prediction with the output.
For a directory r means reading its list of names, x means passing through it to a file by name, and w means adding, removing, or renaming a name. archive has r, so ls printed the name. There is no x, so cat could not get to the file, even though the mode of note.txt itself allows reading.
| Letter | On a file | On a directory |
|---|---|---|
r |
read the contents | read the list of names |
w |
change the contents | create, delete, rename names (together with x) |
x |
run it as a program | pass through to files by name |
Deleting erases a name from a directory's list. So you can delete a file without w on the file itself: the rights of the directory holding it decide.
Your directory ~/inbox (drwxrwxr-x, owned by you) holds old.txt with mode -r--r--r--, owned by root. What will rm -f ~/inbox/old.txt do?
-
rmremoves the file's name from the directory entirely. Erasing the contents would needwon the file itself, which is missing. -
Deleting erases the name from the list of
~/inbox, and you havewandxon that directory. The file's own mode does not decide deletion. -
The file's owner does not decide deletion: the rights of the directory holding the name do. The directory is yours, with
wandx.
Deleting changes the directory's list of names, so w and x on ~/inbox allow it. The mode of old.txt affects one thing: without -f, rm asks for confirmation first because the file is write-protected.