The time command in Linux runs the specified program command with the given arguments. When command finishes, time writes a message to standard error giving timing statistics about this program run. It shows

  • Elapsed real time between invocation and termination
  • User CPU time, i.e. amount of CPU time spent in user mode
  • System CPU time i.e. amount of CPU time spent in kernel mode.

bash shell have a built-in time command that provides similar information on the usage of time and possibly other resources. To access the real command, specify its pathname (/usr/bin/time).

Syntax

Following is the syntax of this command

time [options] command [arguments...]

If command was invoked, the exit status is that of command. Otherwise, it is 127 if command could not be found, 126 if it could be found but could not be invoked, and some other nonzero value (1–125) if something else went wrong.

Time Command Versions

Various shell have their own built-in versions of the time command which might take precedence over other time command. Use the type command to determine whether it is a binary or a built-in keyword.

$type time

# Ouput 
time is a shell keyword

Example

df command calculates free disk space. So following command reports how long it took for the df command to complete.

time df