In my system administration job, I come across this particular requirement quite often: run a command, then confirm how long it took to complete the job. You guessed it right – there's a very easy way to do it.
Using the time command
What you need to do is to use the time command, which takes as a parameter the full command line you need to run. Upon completion of the command, time will report the system resources usage during the execution. All the reported numbers are presented in a simple table.
Here's an example: running du command to confirm the size of a directory while timing the effort and reporting the stats:
ubuntu# time du -sk /var 4228720 /var real 0m17.747s user 0m0.010s sys 0m0.080s
As you can see, first the du command output is shown, and then the table with real, user and system times reported.
Leave a Reply