Understand Read, Write and Execute
Understand Read, Write and Execute
The letters r, w and x look the same in every triplet, but their meaning depends on the entry. For a regular file they concern reading bytes, modifying bytes and executing an appropriate program. For a directory they concern listing names, changing entries and searching through paths.
That directory distinction explains several surprises. You can know a filename without being allowed to list the directory, and deleting a file is not just a question about writing the file's contents. Let's examine the directory side using a classroom folder.
What you’ll learn
- Explain read, write and execute for both files and directories.
- Distinguish changing file bytes from removing an entry in its parent directory.
Directory bits govern names and traversal
Read
Directory read allows listing entry names.
see namesWrite
Write, with required search access, allows changing directory entries.
create or remove namesSearch
Execute/search permits traversal to known entries, subject to other checks.
open classroom/report.txt
Inspect read, write and search on a classroom folder
Prepare the example
Use a new practice folder. The block creates a classroom directory and sets ordinary mode 750 so its triplets are predictable. We are inspecting meanings here, not changing a production report folder's access. Owner, group and others still identify separate classes.
Bash · Linux terminal
mkdir classroom
chmod 750 classroom
ls -ld classroomExpected behavior; machine-dependent details
The mode begins drwxr-x---.For the directory mode 750, the owner gets rwx, the group gets r-x and others get no ordinary bits. Directory read permits listing names, search/execute permits traversing to known entries, and write participates in creating, removing or renaming entries when the other required checks allow it.
Now contrast changing a report's bytes with deleting its name from the parent directory. Those operations act on different objects. A read-only regular file can still be removable by someone with the required parent-directory permissions, subject to sticky, ACL and other rules. Do not use the word 'write' without naming what is being written.
Read the bits on a regular file
The letters r, w and x are the building blocks of traditional Linux permissions. Their meaning depends partly on whether the object is a regular file or a directory.
What do these symbols mean?
- r (read) – Allows viewing the contents of a file or listing the contents of a directory.
- w (write) – Allows modifying a file or adding/removing files in a directory.
- x (execute) – Allows running a file (like a script), or entering a directory.
Let’s see permissions in action
We’ll use the ls -l command to list files along with their permissions.
ls -l
-rwxr-xr-- 1 user user 2048 Jul 1 10:00 hello.sh
This output shows a file named hello.sh. Let’s break down the leftmost part: -rwxr-xr--
Permission breakdown
| Part | Meaning |
|---|---|
| - | It's a file (d for directory, - for regular file) |
| rwx | User (owner) permissions: read, write, execute |
| r-x | Group permissions: read, execute (but not write) |
| r-- | Others: read only |
Interpret the same letters on a directory
Try this example yourself
Create a file and check its default permissions:
touch myfile.txt
ls -l myfile.txt
-rw-r--r-- 1 user user 0 Jul 2 11:30 myfile.txt
This means:
- User can read and write the file
- Group can only read
- Others can only read
What about directories?
Directory permissions behave slightly differently:
- r – Can list directory contents
- w – Can create/delete files in the directory
- x – Can enter ("cd into") the directory
Let’s check a directory’s permissions:
mkdir testdir
ls -ld testdir
drwxr-xr-x 2 user user 4096 Jul 2 11:35 testdir
This means:
- User can list, write, and enter the directory
- Group and others can read and enter, but not modify
Quick tip: Use chmod to change permissions
For example, to add execute permission for everyone on a file:
chmod +x hello.sh
ls -l hello.sh
-rwxr-xr-x 1 user user 2048 Jul 2 11:40 hello.sh
Now everyone can execute the script!
Interpret r, w and x for files and directories
Permissions are crucial to keeping your Linux system secure and organized. Knowing what r, w, and x mean will help you control access to your files and directories with confidence.
In upcoming lessons, we'll explore changing permissions using chmod, chown, and symbolic vs numeric modes. Stay tuned!
Why a read-only file can still be deleted
Think of the report contents and its name in a directory as two different objects you can affect. Writing a new mark changes the file bytes. Removing the report name changes the parent directory entries. That explains why a read-only report can still be removable when the actor has the required write and search access to its parent.
A sticky directory adds restrictions on who can remove or rename entries, and ACLs or other system policy can add further checks. A removal tool may also ask for confirmation on a read-only file; that prompt is not the same as a kernel rule requiring file write access. When predicting the result, name the operation first, then inspect the object whose permissions govern it.
Try it, then check the worked answer
Your task: Which directory permission permits traversal to a known entry?
Use a new practice folder. The block creates a classroom directory and sets ordinary mode 750 so its triplets are predictable. We are inspecting meanings here, not changing a production report folder's access. Owner, group and others still identify separate classes.
Bash · complete example for this question
mkdir classroom
chmod 750 classroom
ls -ld classroomExpected behavior; machine-dependent details
The mode begins drwxr-x---.Worked answer
Execute/search.
Directory execute/search is the bit relevant to traversal of a known entry. Directory read alone is about listing names. File write is about changing the file's bytes, so it does not replace the required traversal access on directories in the path.
Check your decision
Check the important distinction
Directories interpret rwx differently from files
Interpret each bit for the entry type before predicting an operation. Reading names, traversing a path, editing bytes and deleting an entry are different tasks. Identify the file or directory involved in each task, then consider the relevant bits and additional access rules.
Reaching the recap and completing the quizzes are separate milestones.