Is there away that I can run chmod to set the folders at 0755 and the files at 0644, or do I have to apply 0755 to all folders individually?


You can do it with find, either through -exec or a piped command:

find . -type d -print0 | xargs -0 chmod 0755


find . -type d -exec chmod 0755 {} \;

The -type d will process all directories. You can also run the same commands above with -type f to process the files (just make sure to swap the 0755 with 0644).

| improve this answer | |

You can mostly do this with chmod's symbolic mode's "X" permission, which basically means "x, but only when it makes sense":

chmod -R u=rwX,go=rX /path/to/dir

This will automatically set 755 on directories and 644 on files, except that if any files already have any execute permissions it'll assume that's intentional (i.e. they're actually executable files) and set them to 755 as well.

| improve this answer | |
  • Well, not exactly answer to the question, but I use chmod -R +X /path/.. in most cases. However, the mode X doesn't remove existing executable bit from files. – Xiè Jìléi Jul 26 '12 at 0:43

Think simple : only two lines (bash and no python !!!)

first all files (including directories): chmod 644 -R *

then, only sub-directories: chmod 755 -R */

| improve this answer | |
  • 1
    Why specifically mention bash? That looks as if it will work fine in zsh, dash, sh, pinosh, etc etc. – Hennes Sep 30 '14 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.