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
whoelse is logged in before rebooting a shared machine. - Counting the sessions on a server.
- Checking whether a particular user is logged in.
- Recording
whowas 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 exitExamples
List the users logged in
usersxalice alice bobCount the sessions
usersx | wcx -wList each user once
usersx | trx ' ' '\n' | uniqxCheck whether a user is logged in
usersx | grepx -qw alice && echox 'alice is on'Count the sessions of each user
usersx | trx ' ' '\n' | uniqx -cRead the users from a wtmp file
usersx /var/log/wtmpSee the same users with their terminals and times
whoxWarn 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.logList 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
gnuxterminal 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 (
gnuxtheme picks and saves one); GNUX_THEME sets the default.
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: 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