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 :)
I'd like to recursively chmod a directory so that:
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 {} +
I am using this for anything copied from FAT filesystems:
chmod -R a-x+X .
If it does not work, for example on Mac OS X, try the GNU version of the command chmod
:
gchmod -R a-x+X .
Without knowing more about why you're trying to do this, the most common reasons people tend to use are either:
Files and directories are other-writeable
chmod -R o-w /path/to/dir
Files and directories are not group-writeable
chmod -R g+w /path/to/dir
Or, combine the two:
chmod -R o-w,g+w /path/to/dir
Alternately, if you want files and directories to the correct permissions by default, modify the creating process's umask
.
Basically, it's a rare day that it's correct to use numeric modes with chmod
; typically, directories already have the executable bit set and files that don't need it lack it, so why muck around with it at all when the +
and -
operators obviate the need to do so?