Often while executing commands in the command line interface I find myself nervous or anxious. Particularly if I am working in a production machine because I don’t know if and when a command I issued is going to finish. Knowing how long a command is going to take is very useful as I would be able to anticipate it’s completion instead of waiting and looking at a black and white terminal with no progress for hours. This is where the time command is very useful.

The time command is essentially a wrapper for any command executed in a terminal. The time command must precede any other command to be executed, for example:

The above command will copy big_file.tar.gz to big_file_copy.tar.gz and will return how long it took.

The time command will output to standard error three pieces of information. The elapsed real time, this is how long it took from the start of the call to it’s termination. The user CPU time, which is the CPU time spent executing the instructions from the command issued. The last bit of information is the system CPU time. The system CPU contains the time it took to execute the tasks from the command issued.

If we view the output of the copy command we issued earlier

We can see that it took 23 minutes to run through the entire command execution, from me hitting enter until the file was copied to it’s new location. Roughly 360ms for the CPU to execute all command related to cp , and about 1 minute and 25 seconds for the CPU to execute the tasks needed by cp to copy a file.

As you can see the time command is very useful as it allows you to time how long a command takes to execute. You can use it to benchmark scripts that you created, find out how long something is going to take before actually implementing it on a production machine, or you just want to know for curiosity sake.