How to time a command or script


time is a useful utility for measuring the time elapsed (in seconds) after a command is run.

time (YOUR_COMMAND_OR_SCRIPT)

For example:

time (sleep 1)
( sleep 1; )  0.00s user 0.00s system 0% cpu 1.005 total

The output stats are as follows:

  1. the total time elapsed by the command,
  2. the time consumed by system overhead,
  3. the time until the utility is executed to stderr (standard error stream).

If there’s a lot of text in the stdout (standard output) due to the script or command, you can hide it like so:

time (yes hi | head -n 10) 2>&1 1>/dev/null
( yes hi | head -n 10; ) 2>&1 > /dev/null  0.00s user 0.00s system 130% cpu 0.005 total


Please support this site and join our Discord!