Is there a way to time a series of commands in linux?

Perhaps something like this:

/usr/bin/time { ls; pwd; ls }
  • even without the time command this would fail as it needs the final ; i.e. { ls ; pwd ; ls ; } – northern-bradley Nov 3 '18 at 19:07

You could try to wrap it in a shell command:

/usr/bin/time /bin/sh -c 'ls;pwd;ls'
  • 1
    brilliant! the remaining hair on my head thanks you – northern-bradley Nov 3 '18 at 19:05

Using time use () to create a subshell for the commands you wish to time. The syntax would be:

time ( ls; pwd; ls )

If using /usr/bin/time then add the commands to a shell script (for example my.sh) and time the shell script-:

/usr/bin/time my.sh
  • 1
    This works with time but not with /usr/bin/time. Running the command you gave produces -bash: syntax error near unexpected token ls'` – juniper- Jun 17 '13 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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