Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have an installation script that unzips a directory, then recursively chmods its contents.

I'm surprised it takes almost 10 times the time it takes to unzip, to run the following two commands:

find $dir -type f -exec chmod a+r "{}" \;
find $dir -type d -exec chmod a+rx "{}" \;

Am I doing something wrong, is there a faster way to change the chmod of all files and directories?

share|improve this question
One trick I use is just to do a chmod -R on everything (files & directories) then run the find to fix up the directories – jeffatrackaid May 20 '13 at 16:58
You are doing -exec chmod a+r "{}" \; try chmod a+r "{}" + instead. The first will run the command chmod once for every directory. The later command will run chmod a few times, with a list of directories as options (ie chmod dir1 dir2 dir3 dir4). This means far few processes are created. – Zoredache May 20 '13 at 17:01
Could the downvoter/closer explain what's wrong with this question? – Benjamin May 20 '13 at 17:01
I didn't downvote, but your question probably would have been more appropriate over on – Zoredache May 20 '13 at 17:02
Oh, OK, thanks for letting me know :) – Benjamin May 20 '13 at 17:02
up vote 9 down vote accepted

You can get rid of the find commands by using chmod's X flag:

execute/search only if the file is a directory or already has execute permission for some user (X)

This allows you to set the same permissions on files and directories, with directories additionally being executable, with a single command:

$ chmod -R a+rX $dir
share|improve this answer
Now that's a fast alternative! Thanks for your answer. – Benjamin May 20 '13 at 21:25

You could do the following (assumming Linux):

cd $dir
chmod -R a+r .
find . -type d -print0 | xargs -0 chmod a+x

This should be much faster than the combination of the two commands you indicated in your question.

share|improve this answer

Use tar instead. Specifically with the -p, --preserve-permissions, --same-permissions flag.
You won't can't directly zip it, but -z, --gzip, -j, --bzip2 or -J, --xz ought to work well enough. If you really must have zip it's only a | away.

share|improve this answer

Given your command, I'm thinking you are spending time waiting for find not chmod.


chmod -R a+r $dir

The "-R" means recursive

When you run the unzip and other commands preface them with


To get a measurement of the time spent for the various commands.

share|improve this answer
Thanks, but unfortunately this solves only half of the problem (I need a different chmod for directories). – Benjamin May 20 '13 at 17:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.