Linux / Unix: time Command Examples

The time command in Linux and Unix measures the time it takes to run a command or a script. Here are some examples of how to use the time command:

  1. Measure the time it takes to run a command:
    time [command]
  2. Measure the time it takes to run a shell script:
    time sh [script.sh]
  3. Measure the real, user, and system time consumed by a command:
    time -v [command]
  4. Measure the time it takes to run a command and save the output to a file:
    time [command] > [output_file]

Where [command] is the command you want to measure the time for and [output_file] is the file where you want to save the output.

The time command is a useful tool for measuring the performance of commands and scripts, and for optimizing code. The output of the time command can be used to identify performance bottlenecks and to make informed decisions about performance optimization.

Leave a Comment