1. Computing

Discuss in my forum

Example uses of the command "time"

A Brief Introduction

By

If you want to see how much CPU time the command "head -n 10000 largefile.txt" takes, you can use:

time head -n 10000 largefile.txt
At the end of the command output, you would get something like:

real    0m4.866s
user    0m0.001s
sys     0m0.021s
By default it will list the elapsed time (as read from a wall clock), the CPU time used by your process and the CPU time used by the system on behalf of your process. If the Linux server has multiple processor cores you can estimate how much (wall clock) time your job would need if there were no other processes running by dividing the reported CPU time by the number of cores.

In order to access the GNU version of the time command you may have to specify the whole path, such as /usr/bin/time. This version provides more functionality, such as memory and I/O statistics. For example:


/usr/bin/time -f "\n%E elapsed,\n%U user,\n%S system,\n%M memory\n%x status" head -n 10000 largefile.txt
Which will report something like:

0:07.96 elapsed,
0.00 user,
0.01 system,
1 memory
0 status
With the "-f" option you can compose a string to output process information in any format you like. The %E variable contains the elapsed time, %U contains the CPU time for the user's process, the %S variable hold the system CPU time spent on the user's process, %M reports the memory usage in kilobytes, and %x is the status.

For more options and the units of the various measures see the time man page.

  1. About.com
  2. Computing
  3. Linux
  4. Linux / Shell Commands
  5. Example uses of the Linux Command "time"

©2014 About.com. All rights reserved.