Operations 9 min read

Mastering Linux /usr/bin/time: Options, Formats, and Resource Metrics

This guide explains how to use the Linux /usr/bin/time utility to measure program execution time, memory usage, and other resources, covering its syntax, common options, custom format strings, and a comprehensive list of resource specifiers.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering Linux /usr/bin/time: Options, Formats, and Resource Metrics

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 /usr/bin/time utility provides detailed resource information.

The basic syntax is: /usr/bin/time [options] program [arguments] Options are optional flags or values that modify the output. Common options include: -v or --verbose: produce a detailed description. --quiet: suppress status messages. -f or --format: specify a custom output format. -p or --portability: use POSIX‑compatible output. -o FILE or --output=FILE: redirect output to a file (overwrites). -a or --append: append output to the file instead of overwriting.

Running time without options yields a default output similar to:

real %e
user %U
sys %S

Custom formats are defined with a format string containing resource specifiers prefixed by %. Escape sequences such as \t (tab) and \n (newline) are supported. Example:

/usr/bin/time -f "\t%U user,\t%S system,\t%x status" date

This prints user time, system time, and exit status in a tab‑separated line.

Resource Specifiers

The utility can report a wide range of metrics, each identified by a single‑letter specifier (from the manual page). Notable ones include:

C : command name and arguments.

D : average size of the non‑shared data segment (KB).

E : elapsed real (wall‑clock) time ([hh:]mm:ss).

F : major page faults (I/O‑required).

I : file system inputs.

K : average total memory (data+stack+text) in KB.

M : maximum resident set size (KB).

O : file system outputs.

P : CPU usage percentage (user+system / elapsed).

R : minor (recoverable) 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).

Z : system page size (bytes).

c : involuntary context switches.

e : elapsed real time in seconds.

k : signals delivered to the process.

p : average non‑shared stack size (KB).

r : sockets messages received.

s : sockets messages sent.

t : average resident set size (KB).

w : voluntary context switches.

x : exit status of the command.

These specifiers allow you to tailor the output to the exact metrics you need for performance analysis.

Why Use /usr/bin/time Instead of the Shell Built‑in?

The shell’s built‑in time command differs from /usr/bin/time. Invoking time without the full path may call the built‑in, which lacks many options and may produce different formatting. To access the full feature set, use the explicit path or ensure the external binary precedes the built‑in in your PATH.

For detailed information, consult the manual page with man time for the external utility, or use help time for the built‑in version.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceLinuxcommand-lineResource Monitoringtime utilitycustom format
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.