pushplaybang pushplaybang - 18 days ago 4x
Linux Question

When to use -type d-exec chmod 750 / 640 in docker

I've started to work with Docker for local development moving from installing everything on my mac to containers. Looking through a number of projects I regularly see the following shell commands, particularly

find /www -type d -exec chmod 750 {} \; \
find /www -type f -exec chmod 640 {} \;

Firstly, what are they trying to achieve, secondly what do the commands actually mean and lastly why/ when would you want or need to use this?

I recently duplicated and modified another project and found pulling these commands out seemed to make no difference (fair enough it was no longer based on the same base container.... but still).

Any glimmer of enlightenment would be greatly appreciated.


That handy link in the comments below to explain shell tells us:
What: find all the folders in
and execute the chmod command, changing the permissions to 750
- still unsure of 750, and more importantly why you would do this.


The commands sets all files and directories to be readable and writable by the owner, and readable by the group but the files can not be executed by anyone.

You might want to read up on unix permissions in a bit more detail first.

find /www -type f -exec chmod 640 {}

Find all files under /www and set the user to have read, write access (6) and the group to have read access (4). Other users have no access (0).

find /www -type d -exec chmod 750 {}

Find all directories under /www and set the user to have read, write and execute permissions (7) and the group to have read and execute permissions (5) to those directories. Other users have no permissions (0).

Execute permissions on a directory mean that a user can change into the directory and access the files inside. As a directory can't be executed in the sense of a executable file, the execute bit was overloaded to mean something else.

The link Cyrus posted to explainshell.com is an excellent tool as well.