How to make use of time command in Linux

3

Time is the crucial parameter to judge the potency or efficiency of any job. Such a just right processor is judged via just right processing velocity which is evaluated at the foundation of time. Similarly, in Linux, the “time” command is used to judge the processing time taken via other instructions of their execution. There are alternative ways to do the similar job, as an example, we will be able to edit the textual content recordsdata the usage of the vim editor in addition to the nano editor, with the assistance of the time command we will be able to evaluation which editor takes much less execution time, then we will be able to use that editor for textual content modifying functions for higher efficiency.

What is using time command in Linux

In Linux, the time command is used to resolve the execution time taken via the processor to execute the required command.

The common syntax of the usage of the time command:

$ time [options] [command]

The rationalization to the above syntax is:

  • Use the time clause to resolve the time taken via the command
  • Choose any choices in conjunction with the time clause
  • Type the command whose performed time you wish to have to determine

For instance, we execute a command which is able to take 4 seconds execution time and resolve its time the usage of the “time” command:

The output displayed that the command used to be performed in 4.002 seconds, there are 3 forms of values within the output actual, consumer, and sys, the rationale to them is as:

  • Real: This is the true time taken via the processor of the pc to execute the command from urgent the button to finish the command.
  • User: CPU time this is taken via the consumer mode.
  • SYS: This is the time taken via the machine or the Kernel to execute the command.

We too can upload an choice via including a flag of “-p”, that can show the time in transportable POSIX layout, to comprehend it, once more run the above command the usage of the “-p” flag:

We will replace the repository of the Linux and can observe the time of replace via the usage of the time command:

It will take a little time to replace the repository:

It takes 36.289 seconds to replace the programs repository. To perceive extra in regards to the time command, we will be able to run the lend a hand the usage of the command:

If we wish that the output of the time command isn’t displayed at the display screen, as an alternative of that it will have to be stored within the textual content record we will be able to run the next command:

$ /usr/bin/time -o output.txt sleep 4

Note: We will use the “/usr/bin/time” as an alternative of the “time” command for the reason that shell integrated time command does no longer toughen the “-o” choice.

To view the output of the record “output.txt”, use the command:

To have the detailed abstract of the performed time, use the choice “-v” with the “/usr/bin/time” command:

$ /usr/bin/time -v sleep 4

The above determine presentations the detailed abstract of the performed time for the command. In the ultimate, Linux supplies the manuals of all of the integrated instructions, to view the guide of the time command to hunt some knowledge, use:


Conclusion

The time command is utilized in Linux for trying out functions; it’s used to check the efficiency of newly created packages. In this write-up, we now have mentioned using the time command in Linux this is used to watch the execution time of the instructions in Linux. We have mentioned two syntaxes, the integrated “time” command and “/usr/bin/time” command with its other choices.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More