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?
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?
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
Think simple : only two lines (bash and no python !!!)
first all files (including directories): chmod 644 -R *
then, only sub-directories: chmod 755 -R */
1Why specifically mention bash? That looks as if it will work fine in zsh, dash, sh, pinosh, etc etc. – Hennes – 2014-09-30T13:23:13.167
Well, not exactly answer to the question, but I use
chmod -R +X /path/..
in most cases. However, the modeX
doesn't remove existing executable bit from files. – Xiè Jìléi – 2012-07-26T00:43:48.363