Skip to lesson

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.

Beginner to intermediate·13 min·Users and permissions·Updated 2026-11-24

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:

bash
cd ~/project
ls -l README.md src
result
-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.css

The first column, such as -rw-r--r--, has ten characters:

text
-  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 link

Each 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:

  1. If you are the owner, the owner permissions apply, even if the group's are more generous.
  2. Otherwise, if you are in the file's group, the group permissions apply.
  3. 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:

  • r lets you read the contents.
  • w lets you change the contents.
  • x lets you run it as a program or script.

On a directory the same letters mean something different, and this surprises almost everyone:

  • r lets you list the names inside (ls).
  • w lets you create, rename and delete entries inside, no matter who owns those files, as long as you also have x (and the sticky bit, described below, is not set).
  • x lets 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:

bash
stat -c '%A %a %U:%G %n' README.md src/hello.sh docs
result
-rw-r--r-- 644 learner:learner README.md
-rwxr-xr-x 755 learner:learner src/hello.sh
drwxr-xr-x 755 learner:learner docs

The 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:

bash
cat /etc/shadow
result
cat: /etc/shadow: Permission denied

The 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:

bash
umask 022
touch new-file
mkdir new-folder
stat -c '%a %n' new-file new-folder
result
644 new-file
755 new-folder

A 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.

0 / 4 understood
01 What do the three groups of rwx in -rwxr-x--- stand for?
02 What is rw-r--r-- in octal?
03 What does the x permission mean on a directory?
04 What does a leading d in drwxr-xr-x show?

Ready for the next small win?

Mark the lesson complete when you are ready.

Course navigation

Tools and Workflow

Linux Command Line tutorial

Learn to work confidently in the terminal, from your first command to pipes, permissions, scripts and a real log-analysis project.

Your progress 0/43
Learning something new?Explore all courses