Linux Time Command with Examples

Table of Contents
Linux Time Command
Time command in Linux is used to determine total execution time of the given command. Mainly used to check the performance of commands and scripts. Using Time command you can also compare total download time for a file using wget
and curl
commands. In this tutorial, you are going to learn Linux time
Command with Examples.
Basic Syntax of Time Command
Following is the basic syntax for time
command in Linux:
time [-p] command [arguments...]
-p: to print time summary in POSIX form this option is used.
Time Command Versions
Linux shells like Bash, Zsh both have their own version of time
command which takes precedence over GNU time command. So to check whether you are using GNU time
time command or not use the following command:
time
The output should be one of the following:
# GNU time (sh) time is /usr/bin/time # Bash time is a shell keyword # Zsh time is a reserved word
If you didn’t get output like time is /usr/bin/time
then you should use time command like given below. specifying the full path.
/usr/bin/time
Now check the type, you will get time is /usr/bin/time
as output.
Time Command Examples
Following are the examples for time
command.
Check time taken by the df
command
To check time taken by df
command to show free disk space run below command:
time df
The output should be:
Filesystem 1K-blocks Used Available Use% Mounted on udev 3941960 0 3941960 0% /dev tmpfs 794444 1896 792548 1% /run /dev/sda5 51343748 6024104 42681828 13% / tmpfs 3972204 111068 3861136 3% /dev/shm tmpfs 5120 4 5116 1% /run/lock tmpfs 3972204 0 3972204 0% /sys/fs/cgroup /dev/sda6 82045336 2879060 74955588 4% /home /dev/sda2 98304 30413 67891 31% /boot/efi tmpfs 794440 16 794424 1% /run/user/120 tmpfs 794440 32 794408 1% /run/user/1000 real 0m0.004s user 0m0.003s sys 0m0.001s
Check time taken by the wget
command
To check the execution time for wget command for downloading Google Chrome setup file run below command:
time wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
The last portion of output should look like:
2019-02-26 23:21:35 (878 KB/s) - ‘google-chrome-stable_current_amd64.deb’ saved [57089254/57089254] [1]+ Done time wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb?src=0 real 1m4.812s user 0m1.627s sys 0m4.346s
Where,
real: The time from start to finish. (starts when ENTER is pressed)
user: The total amount of CPU time used in User Mode.
sys: The total amount of CPU time used in Kernel Mode.
Conclusion
You have successfully learned Linux time command with examples. If you have any queries please don’t forget to comment below.
LATEST POSTS
-
How to Install Sublime Text 3 on Debian 9
-
How to Install RubyMine on CentOS 8
-
How to Install Composer on Debian 10
-
How to Install VirtualBox on Debian 10
-
How to Install Apache on Debian 9
-
How to Install Yarn on Debian 10
-
How to Install LEMP Stack on Debian 9
-
How to Use Linux Screen Command With Examples
-
How to install Android Studio on Ubuntu 18.04
-
How To Secure Nginx with Let’s Encrypt SSL on Debian 10
-
How to install Java on Ubuntu 18.04
-
Best Ways to Create a File in Linux