What is the use of time command in Linux
In Linux, the time command is used to determine the execution time taken by the processor to execute the specified command.
The general syntax of using the time command:
The explanation to the above syntax is:
- Use the time clause to determine the time taken by the command
- Choose any options along with the time clause
- Type the command whose executed time you want to find out
For example, we execute a command which will take 4 seconds execution time and determine its time using the “time” command:
The output displayed that the command was executed in 4.002 seconds, there are three types of values in the output real, user, and sys, the explanation to them is as:
- Real: This is the actual time taken by the processor of the computer to execute the command from pressing the button to complete the command.
- User: CPU time that is taken by the user mode.
- SYS: This is the time taken by the system or the Kernel to execute the command.
We can also add an option by adding a flag of “-p”, that will display the time in portable POSIX format, to understand it, again run the above command using the “-p” flag:
We will update the repository of the Linux and will monitor the time of update by using the time command:
It will take some time to update the repository:
It takes 36.289 seconds to update the packages repository. To understand more about the time command, we can run the help using the command:
If we want that the output of the time command is not displayed on the screen, instead of that it should be saved in the text file we can run the following command:
Note: We will use the “/usr/bin/time” instead of the “time” command because the shell built-in time command does not support the “-o” option.
To view the output of the file “output.txt”, use the command:
To have the detailed summary of the executed time, use the option “-v” with the “/usr/bin/time” command:
The above figure displays the detailed summary of the executed time for the command. In the last, Linux provides the manuals of all the built-in commands, to view the manual of the time command to seek some information, use:
The time command is used in Linux for testing purposes; it is used to test the performance of newly created applications. In this write-up, we have discussed the use of the time command in Linux that is used to monitor the execution time of the commands in Linux. We have discussed two syntaxes, the built-in “time” command and “/usr/bin/time” command with its different options.