Chapter 5

File Permissions

Linux uses a powerful permissions system to control who can read, write, or execute a file. Understanding this is essential for security and collaboration.

Introduction

File permissions

Reading permissions with ls -l

Reading permissions

Use ls -l to see permissions. Example line:

Terminal
-rwxr-xr-- 1 user group 4096 Jan 1 10:00 script.sh

The first 10 characters describe the file type and permissions.

Permission breakdown

The 10-character block is split into file type + 3 permission sets:

PartMeaning
First character- for file, d for directory, l for symlink, etc.
Next 3 (rwx)Permissions for the owner (read, write, execute).
Next 3 (r-x)Permissions for the group.
Last 3 (r--)Permissions for others (everyone else).

Permission letters

Each position in rwx can be present or replaced with -:

Changing permissions with chmod

You can change permissions using symbolic or numeric modes:

Numeric permission values

Each permission is represented by a number and added together:

Permission setValue
r (read)4
w (write)2
x (execute)1
rwx4 + 2 + 1 = 7
rw-4 + 2 = 6
r-x4 + 1 = 5
r--4

Changing owner and group

Sometimes you change who owns a file or which group it belongs to:

Practice questions

Question 1

Run ls -l in your home directory and copy one example permission string (like -rw-r--r--). Explain what each part means.

Hint: Focus on owner, group, others and r/w/x flags.

Question 2

Write the exact chmod command you would use to make a script run_backup.sh readable and executable by everyone, but only writable by the owner.

Hint: Think about numeric mode: owner = rwx, group = rx, others = rx.

Quiz

Test your understanding. Click an answer to see if it's correct.

1. In the permission string -rwxr-xr--, what does the x in the first group (rwx) mean?

  • The group can execute the file.
  • The owner can execute the file.
  • Others can execute the file.
  • No one can execute the file.

The first rwx block refers to the owner of the file.

2. Which numeric permission value corresponds to rwxr-xr-x?

  • 644
  • 600
  • 755
  • 777

Owner: 7 (rwx), group: 5 (r-x), others: 5 (r-x).

3. Which command adds execute permission for the owner of script.sh without changing anything else?

  • chmod +x script.sh
  • chmod u+x script.sh
  • chmod g+x script.sh
  • chmod 000 script.sh

u stands for user (owner); +x adds execute permission.

4. What does the w permission mean on a directory?

  • You can only read files inside it.
  • You can delete and create files inside that directory.
  • You can execute all files in it.
  • You can rename the operating system.

Write permission on a directory means you can modify its contents.