chmod: the same bits mean different things on files and directories

Updated 25 September 2026

Unix permissions use the same three bits everywhere, but a directory is not a file, and the bits behave differently.

BitOn a fileOn a directory
r (4)Read the contentsList the names inside
w (2)Change the contentsCreate, delete and rename entries (needs x too)
x (1)Run it as a programEnter it and access entries by name

Consequences people trip over

  • Deleting a file needs write permission on the directory, not on the file. You can delete a read-only file in your own folder.
  • A directory without x is a locked door: with r but no x you can see the names inside but can't open any of them.
  • Every parent directory needs x. A web server can't serve /home/ann/site/index.html if /home/ann is 700.

The usual pair: 755 and 644

Directories at 755 let everyone enter and list, while only the owner changes things. Files at 644 are readable by everyone and editable by the owner. Secrets go down to 600 (files) and 700 (directories).

Fixing a whole tree safely

chmod -R 755 site/ also makes every file executable. Treat files and directories separately:

find site/ -type d -exec chmod 755 {} +
find site/ -type f -exec chmod 644 {} +

Or use capital X, which adds execute only to directories (and files that are already executable): chmod -R u=rwX,go=rX site/.

Before reaching for 777

"Permission denied" usually means the wrong owner, not too few permissions. Check with ls -l, fix with chown, and use group permissions (775/664, plus setgid 2775) for shared folders.

More guides