Correct recursive chmod, separate for files & dirs

I'd like to recursively chmod a directory so that:

  • Files are 0664
  • Directories are 0775

How to do it better, shorter, fancier? :) Maybe, use umask somehow?

All find solutions are too long: I always end with Copy-Paste :)


Depending on your version of chmod, you may be able to do this:

chmod -R . ug+rwX,o+rX,o-w

Note the capital X. This sets the executable bit on directories and files that already have any of the execute bit already set.

Note that you can only use capital X with '+', not '=' or '-'.


Better, shorter, fancier than what ?

cd /directory
find . -type d -exec chmod 0755 {} +
find . -type f -exec chmod 0664 {} +

Adding a oneliner to the mix

find -type f -exec chmod 0644 {} + -o -type d -exec chmod 0755 {} +