Master Linux Resource Profiling with the /usr/bin/time Utility
This guide explains how to use the Linux /usr/bin/time command to measure program execution time, memory usage, and other resource metrics, covering syntax, options, custom output formats, and the differences between the built‑in shell time and the external utility.
When you need to analyze a program's performance on Linux—such as user‑mode time, kernel‑mode time, average memory usage, and other metrics—the dedicated utility /usr/bin/time provides detailed resource information.
The basic syntax is: /usr/bin/time [options] program [arguments] Options control which data are displayed and how they are formatted. Common flags include: -v, --verbose: produce a verbose description. --quiet: suppress status messages. -f, --format: specify a custom output format. -p, --portability: output in POSIX‑compatible format. -o FILE, --output=FILE: redirect output to a file (overwrites). -a, --append: append output to a file instead of overwriting.
Running /usr/bin/time ls yields a default output that includes real, user, and sys times, followed by a line of resource statistics such as CPU percentage, maximum resident set size, page faults, and I/O counts.
# /usr/bin/time ls
0.00user 0.00system 0.00elapsed 0%CPU (0avgtext+0avgdata 3888maxresident)k
0inputs+0outputs (0major+304minor)pagefaults 0swapsCustom formats are defined with a format string containing percent‑escaped resource specifiers. For example:
/usr/bin/time -f "\t%U user,\t%S system,\t%x status" dateproduces output like: 0.00 user, 0.00 system, 0 status The format string can include escape sequences (e.g., \t for tab, \n for newline) and literal text. Resources that can be reported include:
C : command name and arguments.
D : average size of non‑shared data segment (KB).
E : elapsed real time (hh:mm:ss).
F : major page faults.
I : file system inputs.
K : average total memory (KB).
M : maximum resident set size (KB).
O : file system outputs.
P : CPU usage percentage.
R : minor (reclaimable) page faults.
S : CPU seconds spent in kernel mode.
U : CPU seconds spent in user mode.
W : number of swaps.
X : average shared text size (KB).
c : involuntary context switches.
w : voluntary context switches.
x : exit status.
Note that invoking time without the full path runs the Bash built‑in version, which lacks many of the formatting options and may produce different output. To view the external utility's manual, run man time; for the built‑in help, use help time.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
