time Command
Beginner Performance & Debugging man(1)Measure command execution time
👁 11 views
📅 Updated: Mar 15, 2026
SYNTAX
time COMMAND
What Does time Do?
time measures the execution time of a command. It reports real (wall clock) time, user CPU time, and system CPU time, providing insight into command performance.
time is available as both a shell built-in and an external command (/usr/bin/time). The external version provides more detail with -v flag. time is essential for benchmarking scripts, comparing approaches, and identifying slow operations.
The three reported times: real = total elapsed time, user = CPU time in user mode, sys = CPU time in kernel mode. real > user+sys indicates I/O waiting.
time is available as both a shell built-in and an external command (/usr/bin/time). The external version provides more detail with -v flag. time is essential for benchmarking scripts, comparing approaches, and identifying slow operations.
The three reported times: real = total elapsed time, user = CPU time in user mode, sys = CPU time in kernel mode. real > user+sys indicates I/O waiting.
Options & Flags
| Option | Description | Example |
|---|---|---|
| command | Time a command | time ls -la / |
| -v | Verbose (external /usr/bin/time) | /usr/bin/time -v ls |
| -o | Write timing to file | /usr/bin/time -o timing.txt -a command |
| -f | Custom format | /usr/bin/time -f '%e seconds, %M KB max' command |
Practical Examples
#1 Time a command
Measures execution time of the find command.
$ time find / -name "*.log" 2>/dev/null
Output:
real 0m2.345s\nuser 0m0.123s\nsys 0m0.456s
#2 Verbose timing
Shows detailed timing including memory usage.
$ /usr/bin/time -v sort large_file.txt > /dev/null
Output:
Elapsed (wall clock) time: 0:05.23\nMaximum resident set size: 524288 kB
#3 Compare approaches
Compares execution time of two different commands.
$ echo "grep:"; time grep -r "pattern" /var/log/ 2>/dev/null; echo "rg:"; time rg "pattern" /var/log/ 2>/dev/null#4 Save timing
Appends timing data to a benchmark file.
$ /usr/bin/time -o benchmark.txt -a ./deploy.sh#5 Script timing
Times an entire command group.
$ time (apt update && apt upgrade -y)Tips & Best Practices
Interpret the three times: real=wall clock, user=CPU in app code, sys=CPU in kernel. real >> user+sys means I/O bound. user >> real means multi-threaded.
Built-in vs /usr/bin/time: Shell built-in time gives basic info. /usr/bin/time -v gives memory usage, page faults, and more detail.
Include all costs: time includes startup time. For short commands, startup may dominate. Run multiple iterations for accurate benchmarks.
Frequently Asked Questions
How do I measure command execution time?
Prefix with time: time command. Shows real (wall clock), user (CPU), and sys (kernel) time.
How do I get memory usage?
/usr/bin/time -v command shows maximum memory (RSS), page faults, and I/O statistics.
What does it mean when real >> user+sys?
The command spent most of its time waiting for I/O (disk, network). It is I/O bound, not CPU bound.
Related Commands
More Performance & Debugging Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →