getutmpx - Linux


Overview

getutmpx is a command-line utility for retrieving information about current system users. It reads the utmpx file, a system database that contains details on active user sessions and login history.

Syntax

getutmpx [options]

Options/Flags

  • -V, –version: Display version information and exit.
  • -h, –help: Display usage information and exit.
  • -w, –who: Print a summarized list of current system users.
  • -p, –processes: Display a list of current processes for the specified user.
  • -u, –user: Filter results to the specified user.
  • -d, –device: Filter results to the specified device.
  • -H, –host: Filter results to the specified host.
  • -a, –all: Display all utmpx entries, including historical ones.

Examples

Display a list of current users:

getutmpx -w

Show processes running for a specific user:

getutmpx -p username

Filter results to a specific device:

getutmpx -d /dev/tty1

Display all utmpx entries, including historical ones:

getutmpx -a

Common Issues

  • Permission denied: Ensure you have appropriate permissions to read the utmpx file.
  • Empty results: Verify that the specified user or device is currently active or has logged in recently.
  • Outdated information: The utmpx database may not always be up-to-date. For the latest user information, use commands like who or finger.

Integration

getutmpx can be used in conjunction with other Linux commands to gather information about user activity. For example:

  • Get a count of current users: getutmpx -w | wc -l
  • Find all logins from a specific host: getutmpx -a | grep 'host=hostname'
  • Automate user monitoring: Create scripts that regularly check getutmpx output for changes and send alerts if necessary.

Related Commands

  • who: Provides a summarized list of current users.
  • w: Shows detailed information about current users, including CPU and memory usage.
  • last: Displays a history of logins, logouts, reboots, and shutdowns.