$_ CLI In Depth
Learning progress 0%
lesson permissions users sudo

Directory Permissions: What x Means on a Folder

6 min read Module 5: Users, Permissions & sudo Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:11

A directory stores names

A directory is a special kind of file. Its contents are a table that maps each name to an inode, which is the object that holds the data and the mode of a file. The permission bits of the directory do not control the files in it. They control what you may do with the table itself. A file deep in a tree is reached by walking the table one name at a time, and each step needs the right bits on the directory it passes through.

This is the reason directory permissions behave differently from file permissions. A file with mode 000 can still be deleted by its owner, if the directory allows the owner to change the table. A file with a perfect mode can be unreachable, if one directory on its path blocks the walk. When you debug a permission error, check every directory from the top of the path down to the file.

Read means list the names

The read bit on a directory lets you read the table, which means you can list the names it contains. The ls command depends on this bit to print the names. Without read, a plain ls fails with Permission denied, even though the files inside might be perfectly readable.

Read alone is not enough to use the files. Listing a name tells you that a file exists, but it does not let you open it. Opening it requires the execute bit on the directory, which is the next meaning.

Execute means enter the directory

On a directory, the execute bit means search. It lets the kernel look up a name in the table and reach the inode behind it. You need search permission to cd into the directory, to open a file by its path, and to run stat on an entry. A directory with read but without execute lets you see names that you can never reach, which is a common source of confusion.

BASH5 lines
mkdir -p demo/inner
echo note > demo/inner/file.txt
chmod 644 demo
ls demo
ls -l demo

The directory demo has mode 644, which gives the owner read and write but no execute. The plain ls demo lists the name inner, because reading the table is allowed. The long form ls -l demo fails for the entries, because it must stat each name, and stat needs search permission. You can see the same effect by trying to read the file through the path.

Write means change the names

On a directory, the write bit lets you add entries, remove them, and rename them. Creating a file, deleting a file, and moving one within the tree all need write on the directory that contains the name. The permission bits of the file itself do not decide whether you may delete it. The directory decides.

This rule is the reason a read-only file can still be deleted. The command rm on a file with mode 444 succeeds when the parent directory is writable by you, and it fails when the directory is not. Many people find this surprising the first time, and it is one of the most useful things to know about the system.

Warning

Write on a directory lets you remove any name in it, including files that belong to someone else. Give write on a shared directory only when every user should be able to change its contents. The sticky bit, in a later unit, is the usual way to prevent that.

Creating and removing entries

Creating a file in a directory needs write and search on that directory. Creating a subdirectory needs the same, because the new directory is an entry in its parent. The mode of the new object is set by the umask, as the umask unit explains, but whether the create succeeds at all depends only on the bits of the directory.

Removing an entry follows the same rule. You need write and search on the directory that contains the entry. The entry itself can have any mode, and it can belong to another user. When you run rm on a file that you cannot write, an interactive shell may ask for confirmation, but the answer does not change the directory check. The directory decides first, and the file mode comes into play only in the confirmation step.

Renaming works the same way, and so does moving a file between two directories. Moving a file from one directory to another needs write on both directories, because the move removes a name from one table and adds it to the other. This is why a move that works inside a single directory can fail across two directories with different permissions.

Why the parent matters for a path

The kernel checks the search bit on every directory in a path, from the top down. Your permission to read a file therefore depends on the whole path, not only on the file and its parent. A common surprise is a deep file in a directory you own, sitting under a parent that you cannot search. The file is unreachable, and changing the file mode does nothing, because the blocking step is higher in the tree.

When a command fails and the file itself looks fine, run stat on each parent directory in turn. The first directory without search permission for you is the culprit, and that is the directory whose mode, or whose owner, needs to change. This walk up the tree is a short and reliable procedure, and it avoids the trial and error of changing modes at random.

Hands-on: see the three meanings

Make a directory, then remove the owner execute bit and try to reach a file inside it. The lab for this unit does exactly that and checks the final mode. The second step makes a directory read-only and asks you to remove a file from it, which is the case where the directory write bit decides the outcome. Work through both, and notice that each check depends on a different bit.

How the kernel decides who may access a file

Visualizer

The kernel picks one class (owner, group or other) and uses only that class’s bits. Directories read r, w and x differently, and the sticky bit limits who can delete.

1 / 4
-type
-owner
-
-
rgroup
w
x
-other
-
-
process
uid 1000, gid 1000
file
owner 1000, group 1000
mode
070

The kernel knows the process’s uid and gid, and the file’s owner and group. It picks exactly one class for the check and tries them in order: owner, group, other.

cd "$(mktemp -d /tmp/perm.XXXX)" && touch own.txt && chmod 070 own.txt && cat own.txt; echo "status $?"; stat -c "%a %A" own.txt
Terminal lab · 2 steps · real Linux in your browser

Directory Permissions: What x Means on a Folder

Remove search permission from a directory, then remove a file from a read-only directory after restoring write.

01
Block access through a directory
The directory /workspace/dirp currently has mode 755 and holds inner/file.txt. Remove only the owner execute bit from /workspace/dirp, so the file inside can no longer be reached by its path.
Show hint for step 1
Use a symbolic mode with u and the minus operator. The resulting octal mode is 655.
02
Delete a read-only file from a directory
The directory /workspace/box has mode 555, and it holds old.txt, which has mode 444. Add write for the owner to the directory, then remove old.txt with rm -f. The directory must still exist afterward.
Show hint for step 2
The file mode does not matter here. The directory write bit decides whether the entry can be removed.
Check yourself Question 1 of 4
Concept Check Entering a directory recall

Which permission on a directory lets you reach its entries by name, for example with cd?

Recap & Key Takeaways

Read on a directory lets you list its names, and execute lets you search and reach entries by name.
Write on a directory lets you add, remove, and rename entries, and the directory decides whether a file can be deleted.
A directory with read but no execute shows names that you cannot open or stat.
When a path fails, check execute on every directory from the top of the path down to the file.

Primary Sources & Further Reading

Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue