When profiling scripts, compiling software packages, or troubleshooting sluggish database queries in Linux, software engineers often turn to the time command. However, entering time before a command in Bash or Zsh invokes a lightweight shell keyword built into your terminal environment. While this built-in utility quickly reports real, user, and system CPU times, it completely overlooks essential hardware telemetry—such as maximum RAM consumption, memory page faults, filesystem input/output operations, and process context switches.
To acquire an exhaustive performance profile of any process without installing complex external profilers, Linux includes the standalone GNU time binary, located at /usr/bin/time. When executed with its verbose flag, GNU time exposes granular operating system metrics captured directly by the kernel’s process accounting subsystems. This guide explains how to use GNU /usr/bin/time in the Linux terminal to measure command execution time and deep resource utilisation.
Shell Built-In vs Standalone GNU /usr/bin/time
Understanding the distinction between your shell’s internal keyword and the standalone system binary is vital for effective benchmarking:
| Feature & Metric | Shell Built-In (time command) |
GNU Standalone (/usr/bin/time -v command) |
|---|---|---|
| Source | Built directly into Bash, Zsh, or Fish | External binary located at /usr/bin/time |
| Elapsed Wall Clock Time | Reported in seconds | Reported with sub-second precision |
| CPU Breakdown (User / Sys) | Reported | Reported alongside CPU percentage share |
| Peak Memory Consumption | Not available | Exact Maximum Resident Set Size (RSS) in KiB |
| Filesystem I/O Activity | Not available | Count of block input and output operations |
| Context Switches | Not available | Voluntary and involuntary context switch counts |
If you execute which time or type time in Bash, the terminal indicates time is a shell keyword. To invoke the comprehensive GNU binary, you must specify its absolute path (/usr/bin/time) or prefix the command with a backslash (\time) to bypass shell aliases and built-in keywords.
Installing GNU time If Missing
While many minimal server images include GNU time out of the box, some lightweight container distributions (such as Alpine or minimal Ubuntu installations) omit it. You can install it in seconds using your distribution package manager:
On Ubuntu, Debian, and Linux Mint:
sudo apt update
sudo apt install time -y
On RHEL, Fedora, Rocky Linux, and AlmaLinux:
sudo dnf install time -y
On Arch Linux:
sudo pacman -S time
Running Verbose Resource Audits with the -v Switch
The primary advantage of GNU time is its verbose report mode, enabled using the -v (or --verbose) parameter:
/usr/bin/time -v tar -czf backup.tar.gz /var/log
After the target command completes its task, GNU time outputs a structured summary to standard error:
Command being timed: "tar -czf backup.tar.gz /var/log"
User time (seconds): 1.42
System time (seconds): 0.18
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.63
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 9428
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 2419
Voluntary context switches: 142
Involuntary context switches: 87
Swaps: 0
File system inputs: 4120
File system outputs: 18450
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Interpreting Critical Performance Fields
Several metrics in this output provide immediate diagnostic value when evaluating software efficiency:
- Maximum resident set size (kbytes): Represents the absolute peak RAM the process occupied in physical memory during its execution. In the example above,
9428 kbytesindicates the compression utility required approximately 9.2 megabytes of RAM. - Percent of CPU this job got: Highlights multi-threading efficiency. A single-threaded program operating at full capacity displays near
100%. A multi-threaded task running across 8 CPU cores can reach up to800%. - Major vs Minor Page Faults: Minor faults occur when pages are allocated or relocated in RAM. Major page faults occur when the kernel must read missing pages from physical disk storage, directly impacting execution latency.
- Voluntary vs Involuntary Context Switches: Voluntary switches occur when a process yields CPU execution while waiting for external I/O (such as disk reads or network sockets). Involuntary switches happen when the Linux scheduler forces the task to yield because its assigned time slice expired.
Redirecting Benchmark Reports to a Log File
Because GNU time sends its statistical report to standard error (stderr) rather than standard output (stdout), piping the output into regular files requires the dedicated -o flag:
/usr/bin/time -v -o benchmark_results.txt ./data_processor.sh
The target script’s normal console output continues printing to your terminal undisturbed, while the full profiling data writes cleanly into benchmark_results.txt. To append multiple runs into a single ongoing log file, include the -a (append) flag alongside -o.
Creating Custom Formatted Benchmark Strings
If verbose output produces too much clutter for automated CI/CD pipelines, GNU time allows custom format strings using the -f switch:
/usr/bin/time -f "Elapsed: %E | Peak RAM: %M KB | CPU: %P" python3 script.py
This command prints a clean single-line summary upon termination:
Elapsed: 0:04.12 | Peak RAM: 45120 KB | CPU: 99%
Leveraging GNU /usr/bin/time provides Linux developers and system administrators with a precise, low-overhead profiling tool to measure real-world performance bottlenecks and memory ceilings directly from the terminal.