Recursively chmod directories only
June 19th, 2006find . -type d -exec chmod 755 {} \;
This will recursively search your directory tree (starting at dir ‘dot’) and chmod 755 all directories only.
Similarly, the following will chmod all files only (and ignore the directories):
find . -type f -exec chmod 644 {} \;
This entry was posted on Monday, June 19th, 2006 at 6:24 pm and is filed under Linux. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
November 10th, 2006 at 10:28 am
Thanks!!! It’s amazing how the simplest things can drive you insane.
December 21st, 2006 at 11:35 pm
This was extremely helpful for me too, so thanks for the tip. Exactly what I was looking for.
Now, if you could explain the syntax a little bit in order for us to be able to invent similar constructs? I am trying to understand exactly everything after the 644, that is
{} \;.What does this stand for?
January 19th, 2007 at 6:29 am
Ernesto:
It’s all in
man find. The{}gets replaced by the current filefindis processing (which is why you don’t need to usechmod -R), and\;is just there to mark the end of theexecexpression.January 19th, 2007 at 7:22 pm
This is simply wonderful. Look at my stupidity —
>chmod -Rf ./*.java ./**/*.java ./**/**/*.java ./**/**/**/*.java ……………………
February 19th, 2007 at 10:56 am
Great post - have clipped it for future reference!
I also discovered that you can do (e.g.)
find . -type f -name '*.htm*' -exec chmod 644 {} \;to only apply chmod to files with names matching a specified pattern. Great when you need to clean up after a php application install and set php files to 755, html files to 644, etc….
April 15th, 2007 at 9:54 am
thanks
very cool, you rule!
to restrict to an owner you can also do:
find . -type d -user fileowner -exec chmod 0755 {} \;
July 13th, 2007 at 7:13 pm
This just saved me one huge headache, shows what can be done if you think out of the box..
August 20th, 2007 at 2:17 pm
Wow, thanks all.. *nix is so f-king awesome.
Powerful.. Try doing a rename/repermission like this in windows…. (or dos)
Ron
September 23rd, 2007 at 12:17 pm
[...] /dev/movabletripe » Recursively chmod directories only [...]
November 4th, 2007 at 2:23 am
[...] source: http://movabletripe.com/archive/recursively-chmod-directories-only/ At this source, there is discussion and additional find commands from responders. [...]
November 16th, 2007 at 8:38 pm
Рекурсивна зміна параметрів доступів тільки для файлів чи директорій…
Утилітки chmod та chown не вміють змінювати параметри доступу тільки для файлів, або тільки для директорій. Знайшов цікавий приклад, як таке мо…
December 30th, 2007 at 2:04 am
Thanks!!!
It will also work for .files
February 21st, 2008 at 2:54 am
[...] http://movabletripe.com/archive/recursively-chmod-directories-only/ [...]
March 11th, 2008 at 6:46 am
Perfect, it solved my problem instantly!
March 21st, 2008 at 6:28 am
Thanks for the tip! Reading the man page for chmod, I came across another tip for recursive chmod. I often encounter the situation where the ‘user-owner’ permissions are correct, but the ‘other’ permissions have been made too restrictive, disallowing read access. The following command will fix it:
Note that the capital ‘X’ causes it to do the right thing regarding the executable bit: directories will be executable and files will be made executable only if the file is executable for the ‘user-owner’ or ‘group-owner’. Check out the man page for chmod.
BTW, I always like to say ‘user-owner’, ‘group-owner’, and ‘other’, to help me keep straight that ‘u’ is for ‘user-owner’ and ‘o’ is for ‘other’.
March 28th, 2008 at 6:29 am
Another helpful command for changing files of only a specific type/extension is:
find ./ -name *.pdf -exec chmod 755 {} \;
April 6th, 2008 at 8:27 am
Awesome! Thanks for the tip, exactly what I was looking for.
April 8th, 2008 at 4:56 am
Take not to do something silly when mass changing files. I untarred a tarball, and blithely (blindly!) changed files to 644. Of course I needed many configure files to be executable. They weren’t. the build broke. Silly me!
Otherwise, this is what I needed.
June 8th, 2008 at 9:33 am
[...] /dev/movabletripe » Recursively chmod directories only Recursively chmod directories only June 19th, 2006 find . -type d -exec chmod 755 {} ; This will recursively search your directory tree (starting at dir ‘dot’) and chmod 755 all directories only. Similarly, the following will chmod all files only (tags: commandline chmod) [...]