Linux / Unix: time Command Examples

Linux / Unix: time Command Examples

The time command is a utility that displays the time that a command takes to execute. The time command is typically used to measure the performance of a command or a script.

To use the time command, you can type time followed by the command that you want to execute. For example, to measure the time that it takes to execute the ls command, you can use the following command:

re‮ ref‬to:lautturi.com
time ls

This will execute the ls command and display the time that it took to execute, along with the exit status of the command.

The time command displays the time in three parts: the real time, the user time, and the system time.

  • The real time is the elapsed time that it took to execute the command, including any time that the command spent waiting for other resources or processes.
  • The user time is the time that the command spent executing in user mode, which is the mode that most commands run in.
  • The system time is the time that the command spent executing in kernel mode, which is a privileged mode that is used for system-level tasks.

The time command also displays the maximum resident set size (RSS), which is the maximum amount of memory that the command used while executing.

To display additional statistics about the command, you can use the -v option. For example, to display the page reclaims, page faults, and voluntary context switches, you can use the following command:

time -v ls

This will display additional statistics about the ls command, in addition to the time and exit status.

It is important to note that the time command is not built into the Bash shell, and may not be available on all Unix or Linux systems. To use the time command, you may need to install it or use a different shell that supports the time command.

For more information about the time command and its options, you can consult the documentation for your specific Unix or Linux system.

Created Time:2017-10-29 22:09:00  Author:lautturi