Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Jul 20 '12 at 3:38

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

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


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .