Skip to main content
3 of 7
edited title
Karel Bílek
  • 2.1k
  • 5
  • 22
  • 26

How to run time on multiple commands AND write the time output to file?

I want to run time command to measure time of several commands. What I want to do is:

  • to measure the time of running of all of them added together
  • write the time output to a file
  • do write the STDERR from the command I am measuring to STDERR

What I do not want to do is

  • write the several commands into a separate script (why? because all of this is already a script that I am generating programatically, and creating ANOTHER temporary script would be more mess than I want)

What I tried so far:

/usr/bin/time --output=outtime -p echo "a"; echo "b";

doesn't work, time is run only on the first one.

/usr/bin/time --output=outtime -p ( echo "a"; echo "b"; )

doesn't work, ( is unexpected token.

/usr/bin/time --output=outtime -p { echo "a"; echo "b"; }

doesn't work, "no such file or directory".

/usr/bin/time --output=outtime -p ' echo "a"; echo "b";'

doesn't work, "no such file or directory".

time ( echo "a"; echo "b"; ) 2>outtime

doesn't work, since it redirects all STDERR into outtime; I want only the time output there.

And of course,

time --output=outime echo "a";

doesn't work, since --output=outime: command not found.

How to do it?

Karel Bílek
  • 2.1k
  • 5
  • 22
  • 26