Bits about permission bits

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-11-23

What does 755 mean? Would it be OK to chmod -R 755 .?

Each of the three digits represents the permissions to a certain entity :

As for the actual numbers, they are the sums of the permission bits. The components are:

These are then summed. Thus:

Returning to chmod -R 755. This sets read and execute bit on every file in this tree for every user. This is probably a bad call (the execute part)

Instead you just want the execute permission on a directory to allow other users to list the contents of those directories and to cd into them. $ find storage/ -type d -exec chmod 755 {} \;

(Remember: you need execute permissions on a directory to go into it)

How to remember

They are powers of 2:

Trick: Least permission, biggest number.

Sum them together to get desired number: e.g. if you want rwx, then that's 4 + 2 + 1 = 7. If you want your group and others to have read only, then they both get 4. Now concatenate to get 744.

To change many files, globbing does not work. Use chmod -R 744 folder

Resources