Operations 9 min read

Master Linux’s /usr/bin/time: Measure CPU, Memory, and More with Custom Formats

This guide explains how to use the Linux /usr/bin/time utility to analyze program performance—including user and kernel CPU time, memory usage, and other resources—by invoking the command with various options, customizing output formats, redirecting results, and distinguishing it from the shell built‑in time command.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux’s /usr/bin/time: Measure CPU, Memory, and More with Custom Formats

Sometimes you need to analyze a program’s resource usage, such as time spent in user mode, time spent in kernel mode, average memory consumption, and other metrics. Linux provides a dedicated utility called /usr/bin/time that reports this information and can also indicate warnings and exit status when a command fails.

Basic Syntax

The syntax of the time command is: /usr/bin/time [options] program [arguments] In this syntax, options are optional flags that control specific features of the utility.

Common Options

-v, --verbose Show a detailed description of the output.

--quiet Suppress status messages from the time utility.

-f, --format Specify a custom output format.

-p, --portability Produce output conforming to POSIX.

-o FILE, --output=FILE Redirect the output to a file, overwriting it.

-a, --append Append the output to the specified file instead of overwriting.

Default Output Example

# /usr/bin/time ls
0.00user 0.00system 0.00:00.00elapsed 0%CPU (0avgtext+0avgdata 3888maxresident)k 0inputs+0outputs (0major+304minor)pagefaults 0swaps

The last two lines of the output contain the resource usage information.

Format Options

The -f option lets you define a custom format string. Format strings consist of literal text and “resource specifiers” introduced by a percent sign (%). Escape sequences such as \t (tab) and \n (newline) are also supported.

Example:

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

Output:

0.00 user,    0.00 system,    0 status

Resources and Specifiers

The utility can report a wide range of resources, each identified by a single‑letter specifier (from the manual page):

C – Command name and arguments.

D – Average size of the process’s non‑shared data area (KB).

E – Elapsed real (wall‑clock) time [hours:]minutes:seconds.

F – Major (requiring I/O) page faults.

I – Number of file system inputs.

K – Average total (data+stack+text) memory usage (KB).

M – Maximum resident set size (KB).

O – Number of file system outputs.

P – Percentage of CPU used (user+system)/elapsed.

R – Minor (reclaimable) page faults.

S – CPU seconds spent in kernel mode.

U – CPU seconds spent in user mode.

W – Number of times the process was swapped out.

X – Average amount of shared text (KB).

Z – System page size (bytes).

c – Voluntary context switches.

e – Elapsed real time (seconds).

k – Number of signals delivered.

p – Average non‑shared stack size (KB).

r – Number of socket messages received.

s – Number of socket messages sent.

t – Average resident set size (KB).

w – Voluntary context switches (e.g., waiting for I/O).

x – Exit status of the command.

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

Running time without the full path invokes the Bash built‑in, which does not recognize many of the options described above. For example, using time -f "\t%U user,\t%S system,\t%x status" date without the full path results in a “command not found” error for -f and produces output in the default format rather than the requested custom format.

To access the full-featured utility, use the explicit path /usr/bin/time or consult the manual page with man time. The built‑in help can be viewed with help time.

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.

Performance MonitoringLinuxShellresource usagetime command
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.