Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Jul 20 '12 at 3:38

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 7 down vote accepted

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

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

share|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 */

share|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 at 13:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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