LinuxCommandLibrary

groups

Display a user's group memberships

TLDR

Print group memberships for the current user

$ groups
copy

Print group memberships for a list of users
$ groups [username1 username2 ...]
copy

SYNOPSIS

groups [options] [user...]

PARAMETERS

--help
    Display help text and exit.

--version
    Output version information and exit.

DESCRIPTION

The `groups` command displays the list of groups to which the specified user belongs. If no user is specified, it displays the groups of the current user. This command is useful for determining a user's access rights and permissions within the system, as group memberships often dictate what resources a user can access. Understanding group membership is critical for system administration and security auditing. The output is a simple list of group names, making it easy to parse and interpret. It retrieves this information from the `/etc/group` file or a network-based user database (e.g., LDAP). The command is a standard Unix utility and has been available on Linux systems for a long time, providing a consistent way to view group memberships. Using the `groups` command helps when troubleshooting access denials by allowing you to determine if the user has been added to a group that gives rights to the desired resources. It is also an important tool when a script relies on the user being a member of a specific group.

CAVEATS

The output may be truncated if the user is a member of a large number of groups. The group names are resolved using the system's configured name service switch (NSS) configuration.

EXIT STATUS

The `groups` command returns an exit status of 0 on success, and a non-zero value on failure (e.g., invalid user specified).

EXAMPLES

  • To view your own groups: groups
  • To view groups for user 'john': groups john
  • To see all groups a user is a member of: groups

HISTORY

The `groups` command is a core Unix utility that has been present since the early days of Unix. It provides a fundamental functionality for user and group management. Over time, the command has remained relatively unchanged, reflecting its simple but essential purpose. The primary function of `groups` has always been to display a user's group memberships, which is critical for access control.

SEE ALSO

id(1), getent(1), group(5), user(1)

Copied to clipboard