time(1)
Run a program and report how long it takes, plus resource usage.
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
| Flag | What it does |
|---|---|
-f FORMAT | Use custom format string for output (GNU time only); see man page for format codes like %e (elapsed), %U (user), %S (system), %M (max RSS) |
-p | Use POSIX output format (portable across shells); shows real, user, and sys times in seconds |
-v | Verbose output; show detailed resource usage including memory, page faults, I/O (GNU time only) |
-o FILE | Write timing results to FILE instead of stderr (GNU time only) |
-a | Append to output file instead of overwriting (GNU time only, requires -o) |
-h | Print 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 /usrSleep for 5 seconds and report elapsed time (approximately 5.0s real)
time sleep 5Run a script with verbose resource stats; shows max memory used, CPU usage, page faults, I/O counts
/usr/bin/time -v ./heavy_script.shRun make with POSIX-formatted timing; portable output format across systems
/usr/bin/time -p make buildCustom format showing elapsed time and peak memory usage in a readable way
/usr/bin/time -f '%e seconds, %M KB memory' python script.pyTime 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