Bash Wiki
Posts (Latest 30 updated) :
Read all
Contents:
  1. [Linux] Bash time uso equivalente: Measure command execution time
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
    5. Tips

[Linux] Bash time uso equivalente: Measure command execution time

Overview

The time command in Bash is used to measure the duration of execution of a command. It provides valuable information about how long a command takes to run, along with resource usage statistics such as CPU time and memory consumption.

Usage

The basic syntax of the time command is as follows:

time [options] [arguments]

Common Options

  • -p: Use POSIX format for the output.
  • -o FILE: Write the timing output to the specified file instead of standard error.
  • -v: Provide a verbose output that includes more detailed resource usage information.

Common Examples

  1. Basic usage: Measure the time taken by a command.
    time sleep 2
    
  2. Using the -p option: Get the output in POSIX format.
    time -p ls
    
  3. Redirecting output to a file: Save the timing information to a file.
    time -o timing.txt find / -name "*.txt"
    
  4. Verbose output: Get detailed resource usage statistics.
    time -v grep "example" largefile.txt
    

Tips

  • Use time with commands that you suspect may be resource-intensive to analyze their performance.
  • Combine time with other commands in a pipeline to measure the execution time of complex operations.
  • Remember that the time command measures the time of the command itself, not the time taken by any subprocesses it may spawn.