Linux File Permissions Explained
Reading Permission Bits
Run ls -l in any directory and every line starts with ten characters:
$ ls -l notes.txt
-rw-r--r-- 1 alice developers 120 Aug 12 10:30 notes.txt
Breaking down the first ten characters
-rw-r--r--
| Characters | Meaning |
|---|---|
- (position 1) |
File type. - = regular file, d = directory, l = symlink |
rw- (2-4) |
Owner permissions |
r-- (5-7) |
Group permissions |
r-- (8-10) |
Others (everyone else) permissions |
The three permission letters
| Letter | Meaning | On a file | On a directory |
|---|---|---|---|
r |
read | View contents | List the directory's files |
w |
write | Modify the file | Create or delete files inside |
x |
execute | Run as a program | Enter the directory (cd) |
A - in any position means that permission is absent. rw- means read and write, but not execute.
Directories need `x` to enter
A directory with permissions drw-r--r-- cannot be entered with cd, even though the owner can read its file list. The execute bit on a directory means "allowed to traverse into it."
Who is the owner and group?
Looking again at the full line:
-rw-r--r-- 1 alice developers 120 ...
aliceis the ownerdevelopersis the group120is the size in bytes
The three triads apply to exactly these three groups: the owner, members of the group, and everybody else.
Try it
cd ~ && touch demo.txt && ls -l demo.txtls -ld /etc /tmp /home— note the leadingdand the execute bits on directoriesls -lain your home directory — spot the files that start with a dot
Advertisement