How To: Time a Command

Have you ever wanted to know how long it takes to complete a command that you entered in the Linux terminal? Well, wonder no more!

This is going to just be a pretty quick article and easy to follow. There’s not a whole lot to explain and it’s pretty straightforward. Like often, let’s crack open your default terminal by pressing CTRL + ALT + T on your keyboard.

Now, let’s take the command:

Unless you have a lot of files, that completes pretty quickly. But, how fast does it really take? Well, simply add the ‘time‘ command before it. Time is simply described in the man page as:

time – run programs and summarize system resource usage

And, for today, it’s going to be pretty easy to use that command. To find out how long it took to list all the files and folders in a directory, you could use:

Note how it tells you the time beneath the results and, if you want to try something bigger, you can take a look at this command:

That should take a just a little more time, but you can actually see how long it really took by adding ‘time’ in front of it. So:

The output at the end is something like this:

real 0m0.566s
user 0m0.423s
sys 0m0.143s

The ‘real’ is how much time it really took. The ‘user’ is how much time it took for the user. The ‘sys’ is how much time it took for the system – the amount of time that the kernel actually devoted to it.

So, there you have it! You can use the time command to find out how long it takes to run stuff in your terminal. If you’re playing with scripting and you’re looking to optimize it, this is a valuable tool. If you’re just a bit curious, then you now have a new tool.

I told you that it’d be quick and easy! Like always, thanks for reading. Feel free to sign up for the newsletter. I promise to not spam you or sell your email address. 

Smash a Button
[Total: 0 Average: 0]
About Me: I'm just some retired dude with a little bit more free time on my hands. If you want to support the site, why not help yourself out too by ordering some inexpensive web hosting so that you can start your own site?

Linux Tips

This work is licensed under a Creative Commons Attribution 4.0 International License.
Exit mobile version