How to Print Logged In Usernames Using the users Command in Linux

When you are auditing a massive Linux server cluster that is experiencing a catastrophic memory leak, the first diagnostic step is to mathematically identify exactly which human actors are currently manipulating the system. If multiple administrators are executing chaotic commands simultaneously, you need a pristine, unpolluted list of their usernames. To force the Linux kernel to dump a highly sanitized string of active actors, you must use the users command.

Executing the Active User Dump

The users command is an incredibly specialized, minimalist extraction engine. Unlike complex diagnostic commands (like w or who) that flood the terminal with chaotic matrices involving TTY paths, IP addresses, and load averages, the users engine focuses purely on identity.

To execute the extraction, open your terminal and type:

users

The exact millisecond you press Enter, the engine violently queries the system’s active login matrix (usually located deep within the /var/run/utmp file architecture). It extracts the precise usernames, mathematically strips away all surrounding metadata, sorts them alphabetically, and outputs a single, pristine line of text directly to your terminal.

The output will look exactly like this: admin root sysadmin user_3.

Parsing the Data for Automation

Because the users engine outputs a mathematically clean, single-line array separated entirely by standard spaces, it is the absolute optimal tool for piping into automated security scripts.

If you need to algorithmically count exactly how many humans are currently logged in to the server, you do not count them manually. You pipe the output into a word-counting engine:

users | wc -w

The engine instantly counts the strings and outputs a perfect integer (e.g., 4). This allows you to build massive automated alerts that trigger if the active user count mathematically exceeds a specific threshold.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.