Linux Command Line · Lesson 23 of 43
Reading file permissions
Read the permission string of any file in ls -l, understand read, write and execute for owner, group and others, and how they differ for folders.
UNDERSTAND IT. THEN TRY IT.
What you can do after this lesson
You will read the strange-looking string at the start of every ls -l line and know exactly who may read, change or run each file. Permissions are the answer to many "permission denied" errors, and they are central to keeping a Linux system secure.
The permission string
Look at a long listing again:
cd ~/project
ls -l README.md src-rw-r--r-- 1 learner learner 66 Jan 15 2026 README.md
src:
total 12
-rw-r--r-- 1 learner learner 15 Jan 15 2026 app.py
-rwxr-xr-x 1 learner learner 39 Jan 15 2026 hello.sh
-rw-r--r-- 1 learner learner 20 Jan 15 2026 style.cssThe first column, such as -rw-r--r--, has ten characters:
- rw- r-- r--
| | | |
| | | +-- others: everyone else
| | +------- group: members of the file's group
| +------------ owner: the user who owns the file
+---------------- type: - file, d directory, l linkEach of the three groups of three characters says whether read (r), write (w) and execute (x) are allowed. A dash means that permission is missing. So -rw-r--r-- means: a regular file; the owner can read and write; the group can read; everyone else can read.
Whose rules apply?
Linux checks the rules in order and uses the first that fits:
- If you are the owner, the owner permissions apply, even if the group's are more generous.
- Otherwise, if you are in the file's group, the group permissions apply.
- Otherwise, the others permissions apply.
The owner and group are the next two columns of ls -l (here learner learner). The root user bypasses the read and write checks (but even root cannot run a file that has no execute bit at all).
What each permission means
On a regular file:
rlets you read the contents.wlets you change the contents.xlets you run it as a program or script.
On a directory the same letters mean something different, and this surprises almost everyone:
rlets you list the names inside (ls).wlets you create, rename and delete entries inside, no matter who owns those files, as long as you also havex(and the sticky bit, described below, is not set).xlets you enter the directory (cd) and reach files by name.
That is why a folder normally needs x as well as r. A directory with r but no x shows names but refuses access to them, and a directory with x but no r lets you open a file if you know its exact name, but not list it.
Octal numbers
Each permission has a value: r = 4, w = 2, x = 1. Add up the values for each group to get one digit:
| Symbols | Calculation | Digit |
|---|---|---|
rwx |
4 + 2 + 1 | 7 |
rw- |
4 + 2 | 6 |
r-x |
4 + 1 | 5 |
r-- |
4 | 4 |
--- |
0 | 0 |
So -rwxr-xr-x is 755, and -rw-r--r-- is 644. These two are the most common modes: 755 for programs and folders, 644 for ordinary files. stat can print both forms together with the owner:
stat -c '%A %a %U:%G %n' README.md src/hello.sh docs-rw-r--r-- 644 learner:learner README.md
-rwxr-xr-x 755 learner:learner src/hello.sh
drwxr-xr-x 755 learner:learner docsThe format codes are %A for the symbolic mode, %a for octal, %U and %G for the owner and group names, and %n for the name. On macOS, use stat -f '%Sp %Lp %Su:%Sg %N'.
Reading permission errors
When you break a rule, the error says so:
cat /etc/shadowcat: /etc/shadow: Permission deniedThe file /etc/shadow holds password hashes, so only root may read it. A "Permission denied" message is not a bug; it is the system doing its job. The right response is to understand why, not to reach for sudo.
The new-file default: umask
New files do not start with every permission. A setting called the umask removes permissions from the defaults of 666 for files and 777 for directories. The common umask 022 removes write access for group and others, which gives 644 for files and 755 for folders:
umask 022
touch new-file
mkdir new-folder
stat -c '%a %n' new-file new-folder644 new-file
755 new-folderA stricter umask of 077 leaves only the owner with access, which is useful on shared machines.
Special bits, briefly
You will sometimes see s or t in the listing. The setuid bit makes a program run as its owner (this is how passwd can change a protected file). The setgid bit on a folder makes new files inherit its group. The sticky bit (t) on a shared folder such as /tmp stops users deleting each other's files. They are advanced topics, and you should not set them casually.
Common mistakes
Thinking x on a folder means "run". It means "enter and search".
Reading the string left to right as one block. Split it into type, owner, group and others.
Assuming the group applies to the owner too. The first matching class wins, so an owner with fewer rights than the group is blocked.
Treating "Permission denied" as an obstacle to bypass with sudo. Work out which permission is missing first.
Exercise
Write the octal form of -rwxr-x---, -rw-rw-r-- and drwx------. Run ls -l on /etc/passwd, /usr/bin/ls and /tmp and describe each in words, including the owner. Try cat /etc/shadow as a normal user and explain the message.
KNOWLEDGE CHECK
A quick check. You’ve got this.
Try each question. Every answer comes with an explanation.
Ready for the next small win?
Mark the lesson complete when you are ready.