Kahibaro
Discord Login Register

2.4.2 Permission types (r, w, x)

Understanding Permission Types

In Linux, each file and directory has permissions that control what different users can do with it. The three basic permission types are r, w, and x. They have slightly different meanings for files and for directories, so it is important to distinguish between the two.

Remember: Linux checks permissions every time you access a file or directory. If the required permission bit is not set for you (as owner, group, or others), the action is denied.

Read Permission: `r`

Read on regular files

For a normal file, r means the ability to read the contents of the file.

If you have read permission on a file, you can:

You cannot modify or delete the file just with r. Reading does not imply writing.

When you run ls -l, a file that is readable by its owner might look like:

-rw-r----- 1 alice staff 1200 Jan  7 10:00 notes.txt

Here, the first r after the - indicates read permission for the owner.

Read on directories

For a directory, r means you are allowed to list the names of the entries in that directory. It is similar to being able to see a table of contents.

If you have r on a directory but not x, you may see names but still cannot access inside those entries.

With read permission on a directory, you can:

Without r on a directory, the contents of that directory are hidden from you, even if you know specific filenames in it.

Write Permission: `w`

Write on regular files

For a normal file, w means the ability to modify the file’s contents. This includes:

Write permission alone does not allow you to execute the file or read it. It only allows changing the data stored in it.

In ls -l output, write permission for the owner is represented as:

-rw-r----- 1 alice staff 1200 Jan  7 10:00 notes.txt

Here the w in rw- indicates the file is writable by alice.

Write on directories

For a directory, w allows you to change the directory’s contents, which means:

Write permission affects the directory’s list of entries, not the content of the files themselves. You can often delete a file from a directory if you have w and x on the directory, even if you have no permissions on the file’s data.

To create, delete, or rename entries in a directory, Linux requires both w and x on that directory. Write without execute does not let you perform these operations.

Without w on a directory, you cannot add or remove entries there, even if individual files are writable.

Execute Permission: `x`

Execute on regular files

For a normal file, x means you can run the file as a program or script.

If a file has x for you, and the file’s content is a valid binary or script, you can:

If a file is missing x for you, the shell will refuse to run it as a program, even if you can read or write its contents.

Typical executable files appear like:

-rwxr-xr-x 1 root root 12345 Jan  7 09:00 /usr/bin/ls

Here, x appears in all three permission triplets, so everyone can execute it.

Execute on directories

For a directory, x has a different meaning. It controls the ability to enter and traverse the directory.

With execute permission on a directory, you can:

Without x on a directory:

To access a file by path, you must have execute permission on every directory in that path. One missing x on any directory along the path blocks access.

Read and execute together on a directory are common for directories you want to browse and enter. For example:

drwxr-xr-x 2 alice staff 4096 Jan  7 11:00 docs

This allows the owner to read, write, and enter the directory, and others to read and enter it, but not modify it.

Combining `r`, `w`, and `x`

Permissions are usually combined as triplets, for example rwx, rw-, or r-x.

For files:

For directories:

You will see these combinations in the first column of ls -l output, where each set of three characters shows the r, w, x bits for owner, group, and others.

Numeric Representation of Permissions

Permissions are often represented with numbers, where each type has a value:

These values are added within each triplet. For example:

So a permission string like rwxr-xr-- corresponds to:

This is written as 754.

Rule: For each user class (owner, group, others), compute the permission digit as
$digit = 4 \times r + 2 \times w + 1 \times x$,
where each of $r, w, x$ is 1 if present and 0 if absent.

Commands that change permissions often use this numeric form. The details of changing permissions are handled in a separate chapter, but understanding the meaning of r, w, and x and how they combine into numbers is essential before using those tools.

Views: 6

Comments

Please login to add a comment.

Don't have an account? Register now!