When you are compiling massive software packages, running complex database queries, or downloading gigabytes of files via the Linux terminal, you often walk away from your computer to grab a coffee. When you return, the task is finished, but the terminal rarely tells you exactly how long the process actually took. If you are a developer trying to optimize a script, knowing the precise execution time down to the millisecond is critical. Fortunately, Linux has a brilliantly simple utility designed exclusively to measure execution duration.
Using the ‘time’ Command
To measure the duration of any task, you simply place the word time directly in front of the command you want to execute.
For example, if you normally use the sleep command to pause the terminal for 5 seconds (sleep 5), you would run it like this:
- Open your terminal application.
- Type the following command:
time sleep 5 - Press Enter.
The command will run exactly as it normally would. However, the very second the task finishes, the time utility intercepts the output and prints three specific metrics directly below it:
- real: The actual wall-clock time that passed from the moment you pressed Enter until the command finished (e.g., 5.002s).
- user: The total amount of CPU time spent running the actual program code in user-mode.
- sys: The total amount of CPU time spent running system kernel operations (like reading files from the hard drive or opening network sockets).
This works for absolutely any command. If you want to know exactly how long it takes your server to update its package lists, you simply run time sudo apt update. The time tool is completely invisible to the actual command, making it the perfect, non-intrusive benchmarking utility for any Linux system administrator.