Linux time Command Tutorial

Linux is a multitasking operating system that shares resources with different processes. Every process takes some CPU, memory, and similar resources which can be monitored with the time command. The time command is also used for performance testing which is generally used to test and count the performance of the scripts and commands. The time command is provided via shell environments where the metering is done from the shell. The Bash, Zsh provides the time command, and also the GNU project provides the time command as the binary which is located /usr/bin/time .

time Command Syntax

The time command has the following syntax where it is provided as the first word for the given command and then the command or process we want to run is provided.

time OPTION COMMAND 
  • OPTION is used to change the time command behavior.
  • COMMAND is a command which will be run with parameters to monitor performance.

time Command Versions

Linux provides multiple time commands which are provided via Bash, Zsh, or GNU. When the time command is executed in the bash shell the bash version of the time command is run. But the GNU time command provides more features than other commands. The GNU time command can be executed like below.

$ /usr/bin/time

If only the time command is provided generally the Bash or Zsh time command is executed according to the shell type.

$ time

Run time Command

We will use the time command in order to get the performance of downloading a file with the wget command. We will also provide the file path we want to download into the wget command.

$ time wget http://ipv4.download.thinkbroadband.com/20MB.zip
Run time Command

We can see that after the command execution is completed the performance metrics are printed into the console which is named real, user, and sys.

  • real is the duration where how much time it takes to complete given command or task. In this case, the download time is provided as real which is 12 seconds.
  • user is the amount of time the CPU is used to process a given task.
  • system or sys is the total amount of the kernel-mode CPU used to process a given task.
See also  Copy, Cut, and Paste In Vim / Vi

Print In Posix Format

By default the time command prints the duration or time information as an hour, minute, second, etc. But the epoch time can be used to display a command execution time and related information. the -p option can be provided to print time command information in epoch time format.

$ time -p wget http://ipv4.download.thinkbroadband.com/20MB.zip
Print In Posix Format

time Command Help

The help information about the time command can be displayed with the --help option like below.

$ /usr/bin/time --help
time Command Help

Leave a Comment