Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 this command:

time -p sh -c 'command1; command2;'

So command1and command2 is executed and I get the real, user and sys time printed on the console.

But I want that command1; command2; is looped 10 times and then I want to get the time which is used for the two commands.

share|improve this question
up vote 8 down vote accepted

You can write a simple for-loop

 time -p bash -c "for (( i=0; i<10; i++ )); do command1; command2; done;"

Note that I used bash instead of sh for the loop.

share|improve this answer
In bash you can just time (for i in {1..10}; do sleep 1 ; done) – frostschutz Mar 24 '13 at 18:47
@frostschutz: Yours seems like a much better answer. Please post it as an answer. – Chris Page Jan 24 at 21:58

With zsh:

time (repeat 10 {cmd1; cmd2})

zsh's repeat is inherited from csh.

With tcsh:

time repeat 10 eval 'cmd1; cmd2'

Would give you the time for each iteration and the overall time at the end.

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.