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.
The basic syntax of the time
command is as follows:
time [options] [arguments]
-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.time sleep 2
-p
option: Get the output in POSIX format.
time -p ls
time -o timing.txt find / -name "*.txt"
time -v grep "example" largefile.txt
time
with commands that you suspect may be resource-intensive to analyze their performance.time
with other commands in a pipeline to measure the execution time of complex operations.time
command measures the time of the command itself, not the time taken by any subprocesses it may spawn.