Javatpoint Logo
Javatpoint Logo

Linux time Command

Linux time command displays how long it takes to execute a command. It helps in checking the performance of the scripts and commands.

The time command can be run with various arguments (commands). When it is successfully executed, it displays the information about used resources and time by the given command.

Syntax: The basic syntax of the time command is as follows:

Options: Some useful options supported by the time command are as following:

-o FILE, --output=FILE: It is used to specify the resource and uses statistics to a FILE instead of the standard error stream. By default, it deleted the previous file content and overwrote the file.

-a, --append: It is used to attach resources so that information can be used instead of overwriting it in the output file. This option is useful with the '-o' option.

-f FORMAT, --format FORMAT: It is used to use the FORMAT as the format string that controls the output of time.

--help: It is used to display the help documentation that contains the summary of the supported options and usages.

-p, --portability: It is used to use the following options to conform to POSIX standard 1003.2:
real %e
user %U
sys %S

-v, --verbose: It is used to display the output verbosely.

--quiet: It is used for not reporting the status of the program even if it is different from zero.

-V, --version: It is used to display the version information of the installed time command.

Examples of the time command

Let's see the following examples of the time command:

  • How to use the time command
  • Write the output to a file
  • Display the detailed output
  • Customize the output
  • Display the version information
  • Getting Help

How to use the time command

The default use of the time command is pretty straightforward: execute the time command with an input command. It will display the time taken by the given command. Consider the below command:

The above command will display the time taken by the ls command. Consider the below output:

Linux Time

From the above output, the 'real' displaying the clock time that the 'ls' command took from the execution to the termination. The 'user' and 'sys' display the time by the user space and kernel space.

Write the output to a file.

The '-o' option is used to write the output to a file instead of displaying it on the terminal. Consider the below command:

The above command will store the output to the given file. Consider the below output:

Linux Time

from the above output, we can see that the pwd command's output is stored in the file 'time.txt.'

Display the detailed output

The '-v' option is used to display the detailed output. Consider the below command:

The above command will display the output verbosely. Consider the below output:

Linux Time

As we can see from the above output, the detailed description is displayed using the '-v' option.

Customize the output

We can customize the output of the time command by using the 'format' option. It facilitates a set of resource specifiers to fetch the information. For example, execute the below command:

The above command will display the specified information in the given format. Consider the below output:

Linux Time

Display the version information

To display the version information of the time command, execute the command as follows:

The above command will display the installed version of the time command. Consider the below output:

Linux Time

Getting Help

To take the help from the terminal, execute the command with the '--help' option as follows:

The above command will display a list of supported options. Consider the below output:

Linux Time

we can also read the manual of the time command by executing the below command:

It will display the manual page of the time command. It will look like:

Linux Time

Scroll the terminal to read more about the command and press the 'q' key to exit from this manual.


Next TopicLinux zcat




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA