In "File Owners", each file got an owner and a group. The first ten characters of ls -l say what each of them can do:
-rw-r----- 1 ana staff 220 Oct 11 09:15 rota.txtThree permissions
Each set has three places, always in the order r, w, x. A - means that the permission is off.
| Letter | Name | On a file, you can |
|---|---|---|
r | Read | Read the text (cat, grep) |
w | Write | Change the text |
x | Execute | Run the file as a program |
Which set is yours?
The computer checks you against the file, in this order, and uses the first set that matches:
For rota.txt above:
| Account | Set | Can |
|---|---|---|
ana, the owner | rw- | Read and change |
A member of staff | r-- | Read |
| Any other account | --- | Nothing |
Only one set applies. An owner with --- cannot read the file, even if all other accounts can.
root is not checked at all, as you learned in "Run a Command as root with sudo".
Permission denied
When your set does not have the permission, you get Permission denied. This is the error that you saw with grep -r in "Search a Directory with grep -r".