Bash Shell

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.

Profile Photo for Lowell Heddings Lowell Heddings
Lowell is the founder and CEO of How-To Geek. He’s been running the show since creating the site back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work.
Read Full Bio »