If you have a long running script that you are working on improving, it can be useful to figure out exactly how long the script or command takes to run so you'll know for sure whether the next run was faster or slower than the first one.

Luckily there's an easy way to do it using the time command. Simply start with time, and then whatever command you want to run.

time <any command here>

You'll see the output something like this:

And just in case you don't understand the arcane output, the 3 different values mean these things:

  • Real: The actual time from start to finish, which could vary if other things are using up the CPU. This is generally the number you'll care about unless you're testing on a really busy system.
  • User: The time the command took from start to finish running user mode code.
  • Sys: The execution time for system calls in the kernel by the process. It's fairly meaningless for most people by itself.

You can use the combination of User + Sys to actually figure out exactly how long your command took for timing purposes.... but if you're on a test box, Real is simpler.