Operations 9 min read

Master Linux ‘time’ Command: Custom Formats, Options, and Resource Metrics

This guide explains how to use the Linux /usr/bin/time utility to measure program execution time, CPU usage, memory consumption, and other resources, covering its syntax, key options, custom format strings, resource specifiers, and the difference between the external command and the shell builtin.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux ‘time’ Command: Custom Formats, Options, and Resource Metrics

When you need to analyze a program’s resource consumption—such as user‑mode time, kernel‑mode time, average memory usage, and more—Linux provides the dedicated utility /usr/bin/time. It accepts a program name and arguments, then reports detailed resource information, warning you if the command exits with a non‑zero status.

Basic Syntax and Common Options

The general form is: /usr/bin/time [options] program [arguments] Key options include: -v or --verbose: output a detailed description. --quiet: suppress the command’s exit status report. -f or --format: let you control the output format. -p or --portability: produce POSIX‑compatible output.

Default Output Example

Running /usr/bin/time ls without options yields something like:

# /usr/bin/time ls
anaconda-ks.cfg  bin  install.log  install.log.syslog  mbox
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 3888maxresident)k
0inputs+0outputs (0major+304minor)pagefaults 0swaps

The last two lines are the resource information generated by time. The default format corresponds to the following specifiers:

%Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k
%Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps

Custom Format Strings

Using -f (or --format) you can specify exactly which metrics to display. A format string consists of plain text interspersed with “resource specifiers” introduced by a percent sign (%). 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
Sun Jan 22 17:46:58 IST 2012
    0.00 user, 0.00 system, 0 status

Resource Specifiers

Below is a non‑exhaustive list of specifiers taken from the manual page, each followed by a brief description: C: command name and arguments. D: average size of the process’s non‑shared data area (KB). E: elapsed (wall‑clock) time ([hh:]mm:ss). F: major (I/O) page faults. I: file system inputs. K: average total memory (data+stack+text) (KB). M: maximum resident set size (KB). O: file system outputs. P: CPU 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 times the process was swapped out. X: average shared text size (KB). Z: system page size (bytes). c: involuntary context switches. e: elapsed real time (seconds). k: signals received. p: average non‑shared stack size (KB). r: socket messages received. s: socket messages sent. t: average resident set size (KB). w: voluntary context switches. x: command exit status.

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

Invoking time without the full path runs the Bash built‑in, which lacks the extended options such as -f. Attempting time -f "..." date results in a “command not found” error for -f and falls back to the default output format. To access the full feature set, always call the external binary via its absolute path, e.g., /usr/bin/time. You can consult the manual with man time for the external command and help time for the Bash built‑in.

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.

Linuxresource usagetime utility
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.