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!!!
March 13th, 2010 at 12:57 am
[...] /dev/movabletripe » Recursively chmod directories only. Leave a comment | Trackback Mar 12th, 2010 | Posted in Unix Tags: chmod, only, recursively [...]
March 30th, 2010 at 5:17 am
Thanks man! Very good tip!
April 16th, 2010 at 5:18 am
[...] Visto en http://movabletripe.com/archive/recursively-chmod-directories-only/ [...]
April 19th, 2010 at 4:46 pm
Thanks. This is still paying dividends four years hence.
May 17th, 2010 at 12:27 am
Thanks, very useful tip.
But if you need to change only the x permission on directories – which is often the case – you can use chmod alone with X instead of x:
chmod -R ug+X,o-X * will give execute permission for user and group and remove from others only on directories in the subtree * (and won’t change files, x or not x)
May 20th, 2010 at 12:28 am
[...] (via) [...]
May 26th, 2010 at 4:54 am
[...] find . -type f -exec chmod 644 {} ; Solution Credit: MovableTripe [...]
May 29th, 2010 at 6:34 pm
Great thing thanx for sharing u r knowledge
June 2nd, 2010 at 11:48 pm
Very useful, surprised chmod doesn’t have a switch for +/- directories, but this is a great workaround.
June 8th, 2010 at 12:18 am
thanks for the tip. using it on my prestashop tutorial to change folder and files permission. Regards.
June 11th, 2010 at 3:57 pm
Yahoo News…
This is really good news today….
June 21st, 2010 at 4:27 am
Yahoo News…
This is really good news today….
June 21st, 2010 at 4:56 pm
greate !
it’s very useful command for Server managers
Thanks a lot
June 22nd, 2010 at 5:59 pm
Yahoo Movie…
This is really great news today….
July 26th, 2010 at 5:36 am
Good stuff! But the command runs a little slow the way its run.
I propose the following using xarg which does exactly the same thing but executes much quicker:
find . -type d -print0 |xargs -0 chmod 740 # for all directories 740 starting at .find . -type f -print0 |xargs -0 chmod 640 # for all files 640 starting at .
August 11th, 2010 at 1:30 pm
Many thanks – saved a lot of extra, error-prove work…
August 14th, 2010 at 2:02 pm
August 28th, 2010 at 6:36 am
Thanks! This really saved me loads of time.
September 2nd, 2010 at 7:30 pm
I’m grateful to the OP and to all the people that made comments and improvements.
The variation posted by Ralph
find . -type d -exec chmod 755 \"{}\" \;got stuck on a file named $29.00.mp3
Any ideas on how to solve this?
P.S. the version of leancode
find . -type f -print0 |xargs -0 chmod 640does not work on my NAS which runs some kind of Linux and BusyBox v1.1.1 complains that the usage of find and of chmod is wrong
September 14th, 2010 at 8:25 pm
[...] vía [...]
September 16th, 2010 at 3:34 am
Thanks a lot! Bookmarked.
I use this often after I download a WordPress plugin or theme. Out-of-the-box, most of them need file permissions adjusted to work.
October 22nd, 2010 at 5:32 pm
Thank you for this tip.
My shell did not realised \; at the end, so I had to use ‘;’ instead:
find . -type d -exec chmod 755 {} ‘;’
November 5th, 2010 at 3:46 am
The variation posted by Ralph
find . -type d -exec chmod 755 \”{}\” \;
got stuck on a file named $29.00.mp3
Any ideas on how to solve this?
try
find . -type d -exec chmod 755 \’{}\’ \;
$ says the next thing is a shell variable. “” allows parsing of shell variables, ” does not
November 17th, 2010 at 1:09 am
[...] en http://movabletripe.com/archive/recursively-chmod-directories-only/ [...]
December 27th, 2010 at 4:26 am
[...] to the Movable Tripe for providing the above [...]
January 26th, 2011 at 10:15 pm
[...] goes here. (function() {var s = document.createElement('SCRIPT'), s1 = [...]
February 16th, 2011 at 10:21 pm
[...] Credit: here. [...]
February 22nd, 2011 at 10:55 am
Thanks, this post and the responses are very useful!
March 15th, 2011 at 10:02 pm
I don’t think you need find to achieve this.
chmod -R 644 ${dir}
chmod -R +X ${dir}
should do the trick as -X (capital x), only adds the execute flag to directories
April 13th, 2011 at 1:06 am
tanks alot :X
April 13th, 2011 at 1:40 am
thanks is useful article
May 13th, 2011 at 6:14 pm
Cheers dude
May 31st, 2011 at 8:35 am
[...] the files inside? I did. I know I’ve had this problem about a hundred times, googled it, found a solution – and then forgot about it [...]
June 20th, 2011 at 11:36 pm
Thanks a lot. It save lot of my time and hitting keyboard
. Thanks *nix family
August 1st, 2011 at 4:35 pm
[...] Sumber: http://movabletripe.com/archive/recursively-chmod-directories-only/ [...]
September 16th, 2011 at 1:17 am
That did the trick, thanks!
October 30th, 2011 at 12:20 am
Simple and objective! Great post. I made a portuguese version in my blog: http://pedrorocha.net/2011/10/mudar-permiss%C3%B5es-com-chmod-somente-em-arquivos-ou-somente-em-pastas
November 12th, 2011 at 1:25 pm
Free runescape…
[...]I do agree with all of the ideas you have introduced in your post. They are really convincing and will definitely work. Nonetheless, the posts are too brief for starters. May you please prolong them a bit from subsequent time? Thanks for the post….
November 21st, 2011 at 12:05 am
I’ll help some of you save your life. BE SURE to specify the file path of the initial directory because if you make a mistake you will literally CHMOD every single file or folder. I learned that the hard way by making the mistake of thinking I was using the command in the correct directory and I was wrong.
November 28th, 2011 at 3:44 pm
thank you for sharing, this was really useful!
December 21st, 2011 at 12:41 am
2011…
Thanks, I’ve recently been searching for info about this topic for ages and yours is the greatest I have discovered so far. But, what about the conclusion? Are you sure about the source?…
December 22nd, 2011 at 4:08 am
[...] http://movabletripe.com/archive/recursively-chmod-directories-only/ [...]