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) [...]
September 21st, 2008 at 6:17 pm
really useful although I had a problem with directories and files that had spaces and ‘ in them .
find . -type d -exec chmod 755 \"{}\" \;fixed it.September 24th, 2008 at 7:23 am
An excellent find!!
Exactly what I needed to resolve a self imposed problem. Thank you
November 13th, 2008 at 5:19 am
Just what I was looking for.
Thaks a lot.
javier.
November 15th, 2008 at 12:09 am
You can solve the problem with spaces in filenames by using xargs as follows:
find . -type f -print0 | xargs -0 chmod 644This has one additional benefit: you are not calling chmod for every file, xargs takes care to put as many filenames on the command line of a single xargs invocation as possible.
The -print0 and -0 arguments make sure the filelist passed from find to xargs contain null-terminated filenames. Xargs takes these and makes sure one filename is a single argument to chmod.
November 22nd, 2008 at 2:00 pm
thanks a lot, after a first meeting with chmod, i screwed up already, this way i could retain rights of my webpage.
November 26th, 2008 at 11:12 am
thanks everyone for the recursively chmod tips.
December 6th, 2008 at 4:30 am
[...] – Warning: This post is for geeks only! Movabletripe’s post explaining how to recursively chmod only directories has been a helpful reference to me in recent months. However, today I tried to access the site, and [...]
May 3rd, 2009 at 8:09 am
[...] (src: Recursively chmod directories only) [...]
June 3rd, 2009 at 8:56 am
Just what I was looking for to solve crappy Perforce problems, need directories to be writeable and files to be read-only….piece of crap version control
June 8th, 2009 at 11:56 pm
Thanks a lot for this!
Your post is the oldest among the similar, so I guess you deserve all the credit
June 9th, 2009 at 12:34 am
[...] 8th June 2009 Found here. [...]
June 15th, 2009 at 12:36 am
thanks! extended to a useful script that sets my scripts permissions correctly too:
#!/bin/sh
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
find . -type f -name \*.sh -exec chmod 744 {} \;
July 3rd, 2009 at 9:37 am
Sweet,… thanks Mr. Hennessy,…
July 8th, 2009 at 1:10 am
Thanks! A great help!
July 26th, 2009 at 7:50 am
[...] Recursively chmod directories only By maohao Here. [...]
August 19th, 2009 at 7:53 am
just thanks! simple, short and so powerful!!!
October 29th, 2009 at 1:56 am
3 years on and still helping – nice one and thanks!
December 23rd, 2009 at 1:22 pm
Man!! Thank you!!! I did a chomd 777 -R to my Docs folder. Man the funky highlighing was annoying! Thanks again!!!