getutmp - Linux


Overview

getutmp is a Linux command-line utility used to display information about the users currently logged into the system, including their usernames, terminals, login times, and other related data. It’s a valuable tool for system administrators and users who need to monitor or troubleshoot user activity on their machines.

Syntax

getutmp [options]

Options/Flags

  • -a, –all : Display all entries in the utmp file, including those with empty or inactive user records.
  • -f, –file : Specify an alternative utmp file to read from. The default is /var/run/utmp.
  • -h, –help : Display help and usage information.
  • -i, –idle : Only display idle users, i.e., those with a login time older than the current time minus the system’s idle timeout period.
  • -l, –login : Only display logged-in users.
  • -n, –numeric : Display numeric user and terminal IDs instead of usernames and terminal names.
  • -p, –process : Display process information for each user, including the process ID, command name, and arguments.
  • -q, –quiet : Suppress normal output and only display error messages.
  • -s, –socket : Only display users connected via network sockets.

Examples

  • Display all logged-in users:
getutmp
  • Display only idle users:
getutmp -i
  • Display numeric user and terminal IDs:
getutmp -n
  • Display process information for each user:
getutmp -p
  • Read utmp entries from an alternative file:
getutmp -f /tmp/myutmp

Common Issues

  • Empty utmp file: If the utmp file is empty or inaccessible, getutmp will display an error message. Ensure the file exists and has the correct permissions.
  • Incorrect file path: Make sure you specify the correct path to the utmp file using the -f option.
  • Unexpected output: The output format can vary depending on the system and terminal settings. Use the -n option to display numeric IDs for clarity.

Integration

getutmp can be used in conjunction with other commands for advanced tasks:

  • grep: Filter getutmp output to search for specific users or terminals.
  • awk: Parse and manipulate getutmp output to extract specific data.

Related Commands

  • who: Displays information about currently logged-in users in a more user-friendly format.
  • w: Displays information about currently logged-in users and their processes.
  • last: Displays information about past logins.