Last Updated : 11 Sep, 2024
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' command is a powerful tool that allows administrators to view the group memberships of a user and retrieve information about user groups on a Linux System.
Features of the 'groups' Commandgroups [options] [username]Key Options of 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 --help2. `--version`
It will display the version of the `groups` command.
groups --versiongroups --version Examples and Implementation of `groups` command in Linux
Here are some common ways to use the 'groups' command to view user group memberships:
1. Viewing Group MembershipsTo view the group memberships of a user is the most common usage of the `groups` command.
Syntax:
groups [username]
Example: Viewing the groups of a user named demon:
groups demongroups 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.
2. To display group membership for the current userNo username is passed then this will display group membership for the current user.
groupsgroups
Here the current user is a demon. So, when we give "groups" command we only get groups in which 'demon' is a user.
3. Passing 'root' with groups commandIt displays the group memberships for the user account "root"
groups rootgroups root
ConclusionNote: 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.
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4