time Command
Purpose
Prints the time of the execution of a command.
Syntax
time [ -p ] Command [ Argument ... ]
Description
The time command prints the elapsed time during the execution of a command, time in the system, and execution time of the time command in seconds to standard error.
Note: Sleep time is not charged to either system or user time.
The time command is also built into the C shell (csh) and Korn shell (ksh) with a different format. To run the time command while in the csh and ksh shells, enter:
/usr/bin/time
Flags
Item | Description |
---|---|
-p | Writes the timing output to standard error. Seconds are expressed
as a floating-point number with at least one digit following the radix
character. The standard format for this flag is as follows: "real %f\nuser %f\nsys %f\n", <real seconds>, <user seconds>, <system seconds> |
Exit Status
If you use the Command parameter, the exit status of the time command is the exit status of the specified command. Otherwise, the time command exits with one of the following values:
Item | Description |
---|---|
1-125 | Indicates an error occurred in the time command. |
126 | Indicates the command specified by the Command parameter was found but could not be invoked. |
127 | Indicates the command specified by the Command parameter could not be found. |
Examples
- To measure the time required
to run a program, enter:
This command runs the program a.out and writes the amount of real, user, and system time to standard error, in the format specified by the -p flag; for example:/usr/bin/time -p a.out
real 10.5 user 0.3 sys 3.6
- To save a record of the time command
information in a file, enter:
/usr/bin/time a.out 2> a.time
Files
Item | Description |
---|---|
/usr/bin/time | Specifies the path of the time command. |