Linux – Correct recursive chmod, separate for files & dirs

chmodlinuxpermissionsweb

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 🙂

Best Answer

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 '-'.