Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 to chmod and chown hundreds of thousands of files as part of a migration script. Each command takes about an hour and a half to complete. I realized these two operations can be run at the same time which cuts down on running time, which I confirmed by testing in the shell.

I know the trick of pushing commands into the background with '&', but I need to make sure both processes finish before proceeding with the rest of the script.


share|improve this question

Use the wait command.

This demo:

sleep 12&
sleep 15&
echo "jobs are done"

Produces this output:

[1]-  Running                 sleep 12 &
[2]+  Running                 sleep 15 &
jobs are done

There's a fifteen second pause before the last two lines are output.

share|improve this answer

You can capture the pid and use wait.

chmod options
chown options

(should work with bash; details may differ on other shell types)

share|improve this answer

If you need to make sure that both processes are finished before proceeding to the next step, a simple solution would be to write something to a file and check it. Just do a head or cat on the file (with default value 0) and add 1 to the first line. If you detect 2, then both processes are completed. Of course the addition should be done at the very bottom of your scripts.

share|improve this answer

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.