In this article we will show you how to use time command.
For example, if you have two different scripts doing the same job and you want to know which one performs better you can use the Linux time command to determine the duration of execution of each script.
Time Command Versions
type time
# Bash
time is a shell keyword
# Zsh
time is a reserved word
# GNU time (sh)
time is /usr/bin/time
Using Linux Time Command.
time wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.9.tar.xz
What will be printed as an output depends on the version of the time command you’re using:
# Bash
real 0m33.961s
user 0m0.340s
sys 0m0.940s
# Zsh
0.34s user 0.94s system 4% cpu 33.961 total
# GNU time (sh)
0.34user 0.94system 0:33.96elapsed 4%CPU (0avgtext+0avgdata 6060maxresident)k
0inputs+201456outputs (0major+315minor)pagefaults 0swaps
real or total or elapsed (wall clock time) is the time from start to finish of the call. It is the time from the moment you hit the Enter key until the moment the wget command is completed.
user – amount of CPU time spent in user mode.
system or sys – amount of CPU time spent in kernel mode.
Conclusion
By now you should have a good understanding of how to use the time command.