To change permissions on directories only

To change permissions on directories only within a file system use:

find /path-to-top-dir/ -depth -type d -name '*' -exec /bin/chmod -c 0604 {} \;

Command options:

-depth

Do child directory before parent. This is important if restricting the w or x permissions as the restriction might stop the command moving into or changing a sub directory after permission is changed on the parent first.

-type

What to find, d for directories, f for files.

'*'

The ' ' is needed to stop error about the syntax.

{} \;

ls needed to make the output from the find command an operand for the chmod command.
The ; is escaped by the \.

To run the command for files change the -type d to -type f.

Back to GNU/Linux Command Line Tips