Why must a folder be executable?

Directories (they're not typically called folders in *nix) have a different meaning for the permission bits than normal files.

For directories, write allows creating new files and deleting files inside it.

Read allows you to list the files inside of it.

Execute allows you to enter it and access files (or other directories) inside.


Since you can't 'execute' a directory, the execute bit has been put to better use. The execute bit on a directory allows you to access items that are inside the directory, even if you cannot list the directories contents.

$ mkdir -p dir/
$ echo 'Hello World!' > dir/file
$ chmod 000 dir/
$ ls -al dir/
ls: cannot open directory dir: Permission denied
$ cat dir/file
cat: dir/file: Permission denied
$ chmod +x dir/
$ ls -al dir/
ls: cannot open directory dir: Permission denied
$ cat dir/file
Hello World!

From the chmod manpage:

The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), restricted deletion flag or sticky bit (t).


Execute permissions on a directory allow you to traverse it, for using resources contained within it.

Tags:

Linux

Bash