Skip to Content
gnux

uptimex

Tell how long the system has been running.

Mirrors GNU uptime. Run it as uptimex, or as gnux uptimex.

Synopsis

uptimex [OPTION]... [FILE]

GNU reference

Description

uptimex prints, on one line, the current time, how long the system has been up, how many users are logged in, and the load averages: the average number of processes running or waiting to run over the last 1, 5 and 15 minutes (on Linux, processes waiting on disk count too). A load average above the number of CPUs (nprocx) means work is queuing. With FILE, the users and the boot time are read from that utmp file instead of the current records. The boot time comes from /proc on Linux, kern.boottime on macOS and FreeBSD, and the tick count on Windows, where the users are the signed-in sessions; Windows keeps no load average, so that part is left out there, as GNU uptime leaves it out wherever the system cannot report it. If the boot time cannot be found the time up is shown as '????' and the exit status is 1.

gnux's terminal view (BR-13): on a terminal, uptimex draws a panel titled with how long the system has been up, holding the time, the users, each load average as a bar of the load against the CPUs (yellow from 75% of them, red from 90%, full when work is queuing) and the CPU count. --pretty[=WHEN] and --theme=NAME, options of gnux's own, choose the view (GNUX_PRETTY, GNUX_THEME); piped or redirected output is GNU's line.

Permissions

Needs no permissions.

Use cases

  • Checking whether a server rebooted unexpectedly.
  • Seeing at a glance whether a machine is overloaded.
  • Recording uptime and load in monitoring logs.
  • Comparing the load with the CPU count before starting a heavy job.
  • Getting the same summary on Linux, macOS and Windows.

Flags

      --help                     display this help and exit
      --pretty WHEN[="always"]   the gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default
      --theme NAME               color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
      --version                  output version information and exit

Examples

Check how long the machine has been up and how loaded it is

uptimex
Output
 14:03:22  up 3 days  3:19,  2 users,  load average: 0.42, 0.37, 0.31

A server feels slow: compare the load with the number of CPUs

uptimex && nprocx
Output
 10:12:40  up 41 days  2:07,  1 user,  load average: 15.83, 14.90, 12.02
8

Did the server reboot overnight? Check the time up

uptimex
Output
 07:58:01  up  2:11,  0 users,  load average: 0.08, 0.05, 0.01

Log the load every 5 minutes from cron

*/5 * * * * uptimex >> /var/log/load.log

Extract just the 1-minute load average

uptimex | trx -s ' ' | cutx -d, -f4 | cutx -d: -f2
Output
 0.42

Show the boot time itself rather than the time since

whox -b
Output
         system boot  Oct  9 10:44

Read the users and boot time from a saved utmp file

uptimex /var/run/utmp

Wait until the load drops below 1 before starting a backup

until uptimex | grep -q 'load average: 0\.'; do sleepx 60; done; ./backup.sh

Record the uptime in a status report

echox "$(hostnamex): $(uptimex)" >> status.txt

Check several machines' uptime over SSH

for h in web1 web2 db1; do ssh "$h" uptimex; done

Show the uptime in the portable gnux shell, the same on every OS

gnux shell -c 'uptimex && whox -q'

Options

Each option has a page of its own, with its usage and examples.

  • --pretty: The gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default.
  • --theme: Color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default.

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

uptimex --help                # options, first examples, exit status
gnux help uptimex             # this page: the full manual
gnux help uptimex --OPTION    # one option in depth, with its examples

See also

On this page