Skip to Content
gnux

usersx

Print the user names of users currently logged in to the current host.

Mirrors GNU users. Run it as usersx, or as gnux usersx.

Synopsis

usersx [OPTION]... [FILE]

GNU reference

Description

usersx prints the login name of each session on this machine, sorted and separated by spaces on one line; a user logged in more than once appears once per session. With nobody logged in it prints nothing. It reads the same records as whox: the utmp file on Linux and the BSDs (sessions whose process has ended are left out) and utmpx on macOS. FILE reads another file in that format instead, such as /var/log/wtmp, without leaving any session out. On Windows the sessions are the signed-in console and Remote Desktop sessions, and FILE is not supported; in the browser playground there are no records.

gnux's terminal view (BR-13): on a terminal, your own name is in the theme's color for what is yours. The text is GNU's. --pretty[=WHEN] and --theme=NAME, options of gnux's own, choose the view (GNUX_PRETTY, GNUX_THEME); piped or redirected output is always GNU's.

Permissions

Needs read permission on the login records (normally readable by everyone) or on FILE. Writes nothing.

Use cases

  • Seeing who else is logged in before rebooting a shared machine.
  • Counting the sessions on a server.
  • Checking whether a particular user is logged in.
  • Recording who was logged in when a job ran.
  • Listing the users recorded in an old wtmp file.

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

List the users logged in

usersx
Output
alice alice bob

Count the sessions

usersx | wcx -w

List each user once

usersx | trx ' ' '\n' | uniqx

Check whether a user is logged in

usersx | grepx -qw alice && echox 'alice is on'

Count the sessions of each user

usersx | trx ' ' '\n' | uniqx -c

Read the users from a wtmp file

usersx /var/log/wtmp

See the same users with their terminals and times

whox

Warn before a reboot when anyone else is on

[ "$(usersx | trx ' ' '\n' | grepx -vx "$(whoamix)")" ] && echox 'others are logged in'

Log who was on when a job ran

echox "$(datex): $(usersx)" >> jobs.log

List the users in the portable gnux shell

gnux shell -c 'usersx'

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

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

See also

On this page