Open In App

Groups Command in Linux With Examples

Improve
Improve
Like Article
Like
Save
Share
Report

In Linux, there can be multiple users (those who use/operate the system), and groups are nothing but a collection of users. Groups make it easy to manage users with the same security and access privileges. A user can be part of different groups. 

The `groups` is a powerful tool that helps administrators to view the group memberships of a user and retrieve information about user groups on a Linux System.

 Important Points:

  • Groups command prints the names of the primary and any supplementary groups for each given username, or the current process if no names are given.
  • If more than one name is given, the name of each user is printed before the list of that user’s groups and the username is separated from the group list by a colon.

Syntax of the `groups` command in Linux

groups [options] [username]

[Options] Available in the `groups` command

1) `–help`

It provides information about the command’s usage and how to specify the username and the functionality of the command.

groups --help

2)  `–version`

It will display the version of the `groups` command.

groups --version
groups --version

groups –version

Examples and Implementation of `groups` command in Linux

Viewing Group Memberships

To view the group memberships of a user is the most common usage of the `groups` command.

Syntax:

groups [username]

Example: Provided with a username

groups demon
groups demon

groups demon

 In this example, username demon is passed with the groups command and the output shows the groups in which the user demon is present, separated by a colon. 

To display group membership for the current user

No username is passed then this will display group membership for the current user.

groups
groups

groups

 Here the current user is a demon. So, when we give “groups” command we only get groups in which demon is a user.

 Passing root with groups command

It displays the group memberships for the user account “root”

groups root
groups root

groups root

 Note: Primary and supplementary groups for a process are normally inherited from its parent and are usually unchanged since login. This means that if you change the group database after logging in, groups will not reflect your changes within your existing login session. 

Conclusion

In this article we have discussed `groups` command, which is used to view the group memberships of users. It also displays the primary and supplementary groups. We see that it has two options `–help` and `–version` which provide additional information and version details respectively.


Last Updated : 09 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads