users - macOS


Overview

The users command in macOS provides a quick way to view active users currently logged into the system. It lists usernames, real names, and login shells associated with each user.

Syntax

users [options...]

Options/Flags

  • -fh: Show finger-like status information for each user. This includes uptime, start time, idle time, and login details.
  • -f: Show a full list of user information, including real name, full path to login shell, and user ID number.
  • -h: Display help information about the command.
  • -l: Display the full login shell path for each user.
  • -n: Sort the output by username.
  • -r: Sort the output alphabetically by real name.

Examples

List active users:

$ users

Show full user information:

$ users -f

Sort users by real name:

$ users -r

Common Issues

No users listed:

This usually indicates that no users are currently logged in to the system. You can verify this by running who command, which shows all active users.

Integration

The users command can be combined with other tools such as awk, grep, and xargs to perform more complex tasks.

Example: Find the username of the user with the longest idle time:

$ users -fh | awk '{print $5, $1}' | sort -nr | head -1
  • who: Show who is logged into the system
  • w: Show who is logged in and what they are doing
  • finger: Get information about a specific user