A directory is a list of names. Its permissions control that list, not the files in it.
| Letter | On a file | On a directory |
|---|---|---|
r | Read the text | List the names (ls) |
w | Change the text | Add, delete and rename items (needs x too) |
x | Run the file | Go in (cd), and reach the items in it |
ls -ld: the directory itself
ls -l DIR lists what is in the directory. Add -d to see the directory itself:
text
learner@tidepool:~$ ls -ld /srv/shop
drwxr-x--- 2 root staff 4096 Oct 11 09:00 /srv/shopTo reach a file, every directory needs x
To read /srv/shop/rota.txt, you need x on /, on /srv and on /srv/shop, then r on the file. One directory without x stops you:
/x for you: yes
/srvx for you: yes
/srv/shopdrwxr-x---, x for you: no. Permission denied
rota.txt (-rw-r--r--)never checked
When a file's permissions look right but you still get Permission denied, run ls -ld on each directory in its path.
Delete is a change to the directory
rm removes a name from the directory's list. So rm needs w and x on the directory, not w on the file.