The time
command runs another program, then displays information
about the resources used by that program, collected by the system while
the program was running. You can select which information is reported
and the format in which it is shown (see section Formatting the output), or have
time
save the information in a file instead of display it on the
screen (see section Using the time
command).
The resources that time
can report on fall into the general
categories of time, memory, I/O, and IPC calls. Some systems do not
provide much information about program resource use; time
reports unavailable information as zero values (see section Accuracy).
Here is an example of using time
to measure the time and other
resources used by running the program doit
, which is given the
arguments `foo' and `3':
time doit foo 3
Mail suggestions and bug reports for GNU time
to
bug-gnu-utils@prep.ai.mit.edu
.
time
command, and its options.
time
.
time
.
time
output.
time
command
The format of the time
command is:
time [-apvV] [-f format] [-o file] [--append] [--verbose] [--portability] [--format=format] [--output=file] [--version] [--help] command [arg...]
time
runs the program command, with any given arguments
arg.... When command finishes, time
displays
information about resources used by command (on the standard error
output, by default). If command exits with non-zero status,
time
displays a warning message and the exit status.
time
determines which information to display about the resources
used by the command from a format string (see section Formatting the output).
If no format is specified on the command line, but the TIME
environment variable is set, its value is used as the format.
Otherwise, a default format built into time
is used
(see section Formatting the output).
Options to time
must appear on the command line before
command. Anything on the command line after command is
passed as arguments to command.
-o file
--output=file
-a
--append
-f format
--format=format
time
. See section Formatting the output, for more information.
--help
time
and exit.
-p
--portability
real %e user %U sys %S
-v
--verbose
-V
--version
time
and exit.
The format string controls the contents of the time
output.
The format string can be set using the `-f' or `--format',
`-v' or `--verbose', or `-p' or `--portability'
options. If they are not given, but the TIME
environment
variable is set, its value is used as the format string. Otherwise, a
built-in default format is used. The default format is:
%Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k %Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps
The format string usually consists of resource specifiers
interspersed with plain text. A percent sign (`%') in the format
string causes the following character to be interpreted as a resource
specifier, which is similar to the formatting characters in the C
printf
function.
A backslash (`\') introduces a backslash escape, which is translated into a single printing character upon output. `\t' outputs a tab character, `\n' outputs a newline, and `\\' outputs a backslash. A backslash followed by any other character outputs a question mark (`?') followed by a backslash, to indicate that an invalid backslash escape was given.
Other text in the format string is copied verbatim to the output.
time
always prints a newline after printing the resource use
information, so normally format strings do not end with a newline
character (or `\n').
There are many resource specifications. Not all resources are measured by all versions of Unix, so some of the values might be reported as zero. Any character following a percent sign that is not listed in the table below causes a question mark (`?') to be output, followed by that character, to indicate that an invalid resource specifier was given.
The resource specifiers, which are a superset of those recognized by the
tcsh
builtin time
command, are:
%
C
D
E
F
I
K
M
O
P
R
S
U
W
X
Z
c
e
k
p
r
s
t
w
x
To run the command `wc /etc/hosts' and show the default information:
time wc /etc/hosts
To run the command `ls -Fs' and show just the user, system, and total time:
time -f "\t%E real,\t%U user,\t%S sys" ls -Fs
To edit the file bork and have time
append the elapsed time
and number of signals to the file `log', reading the format string
from the environment variable TIME
:
export TIME="\t%E,\t%k" # If using bash or ksh setenv TIME "\t%E,\t%k" # If using csh or tcsh time -a -o log emacs bork
The elapsed time is not collected atomically with the execution of the
program; as a result, in bizarre circumstances (if the time
command gets stopped or swapped out in between when the program being
timed exits and when time
calculates how long it took to run), it
could be much larger than the actual execution time.
When the running time of a command is very nearly zero, some values (e.g., the percentage of CPU used) may be reported as either zero (which is wrong) or a question mark.
Most information shown by time
is derived from the wait3
system call. The numbers are only as good as those returned by
wait3
. On systems that do not have a wait3
call that
returns status information, the times
system call is used
instead. However, it provides much less information than
wait3
, so on those systems time
reports the majority
of the resources as zero.
The `%I' and `%O' values are allegedly only "real" input and output and do not include those supplied by caching devices. The meaning of "real" I/O reported by `%I' and `%O' may be muddled for workstations, especially diskless ones.