$linuxjunkies
>

time(1)

Run a program and report how long it takes, plus resource usage.

UbuntuDebianFedoraArch

Synopsis

time [OPTION]... COMMAND [ARG]...

Description

The time command executes a program and measures its execution time. It reports real elapsed time (wall clock), user CPU time, and system CPU time. It also shows memory usage and other resource statistics depending on the shell and options used.

There are two versions: the bash built-in time keyword and /usr/bin/time (GNU time). The external version provides more detailed output and formatting options. Most modern shells default to the built-in, but you can force the external version with an absolute path.

Common options

FlagWhat it does
-f FORMATUse custom format string for output (GNU time only); see man page for format codes like %e (elapsed), %U (user), %S (system), %M (max RSS)
-pUse POSIX output format (portable across shells); shows real, user, and sys times in seconds
-vVerbose output; show detailed resource usage including memory, page faults, I/O (GNU time only)
-o FILEWrite timing results to FILE instead of stderr (GNU time only)
-aAppend to output file instead of overwriting (GNU time only, requires -o)
-hPrint sizes in human-readable format (e.g., 1K, 234M) instead of bytes (GNU time only)

Examples

Run ls and display how long it took; shows real, user, and sys times

time ls -la /usr

Sleep for 5 seconds and report elapsed time (approximately 5.0s real)

time sleep 5

Run a script with verbose resource stats; shows max memory used, CPU usage, page faults, I/O counts

/usr/bin/time -v ./heavy_script.sh

Run make with POSIX-formatted timing; portable output format across systems

/usr/bin/time -p make build

Custom format showing elapsed time and peak memory usage in a readable way

/usr/bin/time -f '%e seconds, %M KB memory' python script.py

Time a bash loop; separates real time (I/O wait) from user CPU time (computation)

time -p bash -c 'for i in {1..1000}; do echo $i > /dev/null; done'

Append timing results to a log file for benchmarking multiple runs

/usr/bin/time -o timings.log -a ./process_data

Related commands