users - Linux


Overview

The users command in Linux displays the usernames of users currently logged into the system. It is typically used for monitoring and administration purposes, helping system administrators quickly assess which users are active on the machine.

Syntax

The syntax for the users command is simple:

users [OPTION]... [FILE]
  • [OPTION]...: This represents options that can modify the behavior of the command.
  • [FILE]: An optional argument specifying a file, typically /var/log/wtmp, from where the command reads the login information. If omitted, it defaults to reading from the current system state.

Options/Flags

The users command generally has a minimal set of options, notably:

  • -h, --help: Display a help message and exit.
  • -V, --version: Output version information and exit.

Examples

Here are some examples of how to use the users command:

  1. Basic Usage:
    Display the names of users currently logged on:

    users
    
  2. Specifying a File:
    Read user information from a specific file:

    users /var/log/wtmp
    

Common Issues

  • File Permissions: If trying to read from a log file such as /var/log/wtmp, ensure you have the necessary permissions. Otherwise, you might encounter a “Permission denied” error.
  • Confusion with Logged Out Users: Note that users reports users currently logged in. If a user has multiple sessions, their name will appear multiple times.

Integration

The users command can be combined with other commands for more comprehensive system monitoring:

  • Counting Logged-in Users:
    Combine users with wc to count the number of users:

    users | wc -w
    
  • Sort and Unique Count:
    To see a sorted list without duplicates:

    users | tr ' ' '\n' | sort | uniq
    
  • who: Shows who is logged on along with additional details like terminal line, login time, and more.
  • w: Provides a detailed view of the users logged into the machine, what they are doing, and system load information.

Exploring further can be done through manual pages (man users, man who, man w) or other online Linux documentation resources.

By combining these commands, system administrators can efficiently monitor user activity and system status, integrating findings into scripts or system checks to enhance operational workflows.