2

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?

3 Answers 3

7

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

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

or

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

2

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.

1
  • 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. Jul 26, 2012 at 0:43
1

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

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

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

1
  • 1
    Why specifically mention bash? That looks as if it will work fine in zsh, dash, sh, pinosh, etc etc.
    – Hennes
    Sep 30, 2014 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.