Linux / Unix: groups Command Examples

The groups command in Linux and Unix is used to display the groups that a user belongs to. Here are some common examples of how to use the groups command:

  1. Display the groups that the current user belongs to:
    groups

    This will display the groups that the current user belongs to, separated by spaces.

  2. Display the groups that a specific user belongs to:
    groups <username>

    Replace <username> with the name of the user that you want to find the groups for.

  3. Display the names of all the groups on the system:
    getent group

    This will display a list of all the groups on the system, including the group name, password, and list of members.

Here are some examples of using the groups command:

$ groups
john

$
groups john
john : john sudo

$
getent group
root:x:0:
bin:x:1:
sys:x:2:
adm:x:4:syslog,john
...

In the first example, the current user (john) belongs to the john group. In the second example, the user john belongs to the john and sudo groups. In the third example, the getent group command is used to display a list of all the groups on the system.

(https://plumascounty.org)

Leave a Comment