When you are managing a multi-user Linux server, it is critical to know exactly who else is actively connected to the system. Whether you need to warn users before initiating a system reboot, or you suspect unauthorized SSH activity, you need a quick way to audit the current login sessions. While commands like who and w provide detailed, verbose tables of login times and IP addresses, sometimes you just need a clean, bare-bones list of user names for a script. For this, you should use the Linux users command.
How the users Command Works
The users command is a simple, highly focused utility that parses the system’s /var/run/utmp file (the master record of all current logins) and extracts only the usernames. It strips out all formatting, IP addresses, and timestamps, returning a space-separated list of active users.
Basic Usage
To print the usernames of everyone currently logged into the server, simply type the command and press Enter.
users
The output will be printed on a single line:
admin root sarah sarah
Understanding Duplicate Names
You will frequently notice that the users command prints the exact same username multiple times (e.g., sarah sarah). This is not an error. The command prints a username for every single active login session.
If the user “sarah” has opened three different terminal windows on her desktop, or if she has established three separate SSH connections to the server from her laptop, her name will appear three times in the output. This accurately reflects the number of terminal sessions she is currently consuming.
Scripting with the users Command
Because the output is completely devoid of headers and formatting, it is perfect for basic bash scripting. For example, if you want to quickly calculate the total number of active terminal sessions on the server without parsing the complex output of the w command, you can simply pipe the output of users into the wc (word count) command.
users | wc -w
This will instantly return a single integer representing the total number of connected user sessions, making it an excellent one-liner for system monitoring dashboards.