Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Linux permissions: read and understand file rights

By updated

Improve this page

The ls -l command shows a series of rwx letters next to each file: those are the permissions. They decide who can read, change or run a file. Knowing how to read them is essential before changing them, and that is what this guide is about.

What you will learn

  • Decode each column of ls -l
  • Understand r, w, x applied to a file
  • Understand r, w, x applied to a directory
  • Tell apart the owner, the group and the others
  • Know the role of umask (default permissions)

How do you read the output of ls -l?

Terminal window
ls -l
Output
total 20
-rw-rw-r-- 1 bob bob 2048 Apr 6 2025 archive.tar
drwxrwxr-x 2 bob bob 4096 Nov 20 10:00 projects
-rw-r--r-- 1 bob bob 4096 Nov 20 10:00 report.txt
-rwxr-x--- 1 bob dev 8192 Nov 20 10:00 script.sh

The first line, total 20, gives the disk space used by the listed files, in 1 KB blocks. The following lines are sorted alphabetically by name.

Each line reads from left to right:

PositionExampleMeaning
1st character- or dType: - = file, d = directory, l = link
Characters 2-4rw-Rights of the owner (user)
Characters 5-7r--Rights of the group
Characters 8-10r--Rights of the others (everyone else)
Number1Number of links (no effect on the rights)
Name 1bobOwner of the file
Name 2bobGroup of the file
Size4096Size in bytes
Date and timeNov 20 10:00Date and time of last change (the year replaces the time for an old file)
Namereport.txtName of the file or directory

The last three lines in the example come from recent changes, so ls -l shows the time (10:00). archive.tar is more than six months old, so ls -l shows the year instead of the time (Apr 6 2025). A file dated in the future, because of a wrong clock, also gets the year. This rule comes from the GNU coreutils documentation ("Formatting file timestamps").

The day and the month name depend on the system language. The example above comes from a C.UTF-8 session, which shows English month names (Apr, Nov) with the month before the day. With the fr_FR.UTF-8 locale, the same directory displays like this:

Output with LC_ALL=fr_FR.UTF-8
total 20
-rw-rw-r-- 1 bob bob 2048 6 avril 2025 archive.tar
drwxrwxr-x 2 bob bob 4096 20 nov. 10:00 projects
-rw-r--r-- 1 bob bob 4096 20 nov. 10:00 report.txt
-rwxr-x--- 1 bob dev 8192 20 nov. 10:00 script.sh

The day comes before the month, and long month names are abbreviated: nov., déc., janv., but avril is written in full, like mars, mai, juin and août. The date column has a fixed width, hence the padding spaces.

On RHEL and its derivatives, the rights are often followed by an eleventh character, a dot (-rw-r--r--.). It means that the file has an SELinux context, the access control system of RHEL. It does not change how you read the rights. A + in that place means that the file also has ACLs.

What do r, w and x mean?

The same three letters apply to files and to directories, but they do not protect the same thing. On a file they protect its contents; on a directory they protect its list of names.

On a file

PermissionLetterMeaning
ReadrRead the contents of the file
WritewChange the contents of the file
ExecutexRun the file (script, program)

A dash - in place of a letter means that the permission is absent.

Concrete examples:

PermissionsMeaning
rw-Read and write, no execute
r--Read only
rwxEvery right
---No right

On a directory

The same letters have a different meaning for directories:

PermissionLetterMeaning on a directory
ReadrList the contents (ls)
WritewCreate, rename or delete files in the directory (with x)
ExecutexEnter the directory (cd) and reach the files

To read the rights of a directory itself, and not those of the files it contains, add -d to ls -l:

Terminal window
ls -ld projects
Output
drwxrwxr-x 2 bob bob 4096 Nov 20 10:00 projects

The leading d marks a directory, and rwxrwxr-x reads as for a file: the owner and the group can list, enter and create files, the others can only list and enter. Without -d, ls -l projects would show the contents of the directory.

Deleting a file: the directory decides

This point is surprising. Deleting a file does not write to the file: the operation removes its name from the directory that holds it. rm does this through the unlink system call, a kernel function that removes a name from a directory. The rights checked are therefore those of the directory, not of the file: you need the w (change the list of names) and the x (go through the directory to reach the file).

A file with no rights at all (----------) can therefore be deleted if you have the w on its directory. Conversely, a file in rwxrwxrwx cannot be deleted in a directory where you do not have the w. The permissions of a file protect its contents; those of the directory protect its name and its existence.

For the file with no rights, rm asks for confirmation in a terminal (rm: remove write-protected regular empty file 'zero'? on Debian 13 for an empty file). Without a terminal, for example in a script, it deletes without asking, and rm -f never asks for confirmation.

Three exceptions reverse this rule, documented in unlink(2):

  • the sticky bit (chmod +t, the t of /tmp): in a shared directory, only the owner of the file (or of the directory, or root) can delete it, even if everyone has the w;
  • the immutable attribute (chattr +i): deletion refused, even to root, whatever the permissions;
  • a file system mounted read-only: no deletion possible.

What are the three levels of rights?

The 9 permission characters are split into three groups of three:

rwx r-x r--
─── ─── ───
u g o
LevelLetterApplies to
User (owner)uThe owner of the file
GroupgThe members of the file's group
OthersoEvery other user

The system checks the rights in this order:

  1. Are you the owner? → u rights apply
  2. Are you a member of the group? → g rights apply
  3. Otherwise → o rights apply to the others

The animation shows how the kernel decides on an access. Choose who asks (bob the owner, alice from the group, eve another user), the action and the rights on the file, then see which series of rights stays lit: only one is examined. With "Delete", the kernel reads the rights of the directory, not those of the file. The animation leaves out root, ACLs and the deletion exceptions listed above.

  • the request targets this file or folder
  • rights read by the kernel
  • the kernel moves on
  • series used, or access granted
  • access denied
  • not checked

How do you decode common examples?

PermissionsWho can do what
-rw-r--r--Owner reads and writes. Group and others only read.
-rwxr-xr-xOwner has every right. Group and others read and execute.
-rwx------Only the owner has access. Nobody else can do anything.
drwxr-xr-xDirectory open to everyone, but only the owner can create files in it.

To practise, run ls -la in your home directory:

Terminal window
ls -la ~/

Try to decode each line: who is the owner? which group? which permissions for each level?

Your turn

The file journal.txt is -r--r--r-- (read-only for everyone). You own the file and the directory that holds it, a drwxr-xr-x directory. Can you change its contents? Can you delete it?

A hint

For each action, ask yourself what it touches: the contents of the file, or the list of names in the directory.

I have tried: show the answer

You cannot change the contents: as the owner of the file you fall in the u block, which is r-- and gives no w. You can delete it: the directory gives you rwx as its owner, so you have the w and the x needed to remove a name from its list. The rights of the file do not count for deletion.

What does umask do?

When you create a file, it does not get rwxrwxrwx by default. A mask called umask automatically removes some permissions.

Rights and the umask can also be written with digits, using the octal notation: one digit per level, in the order owner, group, others. Each letter is worth a number, r = 4, w = 2 and x = 1, and a digit is the sum of the letters present: rw- makes 4 + 2 = 6, r-x makes 4 + 1 = 5, r-- makes 4. So rw-r--r-- is written 644 and rwxr-xr-x is written 755. The guide Change rights with chmod, chown and chgrp teaches how to set them. An extra leading 0 (0022) stands for the special rights, such as the sticky bit: read the last three digits.

Terminal window
umask
Usual output
0022

The value depends on the distribution and the account. On Debian 13, root gets 0022, and an account created with useradd with its own group of the same name (bob in the group bob) gets 0002, which leaves w to the group. The examples on this page use 022.

The 022 umask means that the w permission is removed for the group and for the others: the 0 removes nothing from the owner, each 2 removes the w. The umask does not do a subtraction: each digit designates bits to remove, and a bit that is absent from the start stays absent. That is why a new file, which starts without x, never gains one:

CreationWithout umaskWith umask 022Result
File666 (rw-rw-rw-)w removed for group and others644 (rw-r--r--)
Directory777 (rwxrwxrwx)w removed for group and others755 (rwxr-xr-x)

Troubleshooting

Most permission errors come down to a level you did not expect, or to a directory on the path rather than the file itself. Before changing anything, read the rights of the file and of its parent with ls -ld.

SymptomLikely causeFix
Permission denied when reading a fileNo r right for your levelCheck with ls -l and ask the owner
Permission denied when entering a directoryNo x right on the directoryCheck with ls -ld directory/
A new file is readable by everyone although it should not beDefault umask 022, which leaves r to othersumask 077 in the session (no rights for the group and the others), or chmod on the file already created, see Change rights
ls works but cat file does notTwo possible causes: the file has no r right for your level (and cd into the directory succeeds), or the directory has r without x (and cd fails)Try cd directory/: if it succeeds, read the rights of the file with ls -l; otherwise the directory is missing the x

Key points

  • ls -l shows permissions in the form rwxrwxrwx: owner, group, others.
  • r = read, w = write/change, x = execute (file) or enter (directory).
  • The system checks a single level: user → group → others, in that order.
  • Deleting a file depends on the directory (w + x), not on the file: a file with no rights at all (----------) is not protected from deletion. Exceptions: sticky bit, chattr +i, read-only file system.
  • umask decides the default permissions of new files: 022 gives 644 to files and 755 to directories.
  • For a file older than six months or dated in the future, ls -l shows the year instead of the time.

Knowledge check

Check that the essentials of this guide stuck. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer