chmod

Recursively fixing file permissions

Submitted by fago on Sun, 03/01/2015 - 16:22

When you want to recursively fix file permissions, directories usually should get a umask of 755 while files should default to 644 unless they are scripts.

Fortunately, chmod has the +X modifier for that: +X only adds the execution bit to directories, while it does not add it to files. It keeps pre-existing execution bits for files though. Thus, to fix all directories to have 755 and files to have 644 or 755 depending on the existing exexcution bit, just run:

chmod -R =rwX .

If you want to reset all files to 644 also, run

chmod -R -x,=rwX .

Tags