How to Run ‘groups’ command in Linux
In Linux, there is user and groups; users use the system, and groups are logical frameworks for managing a set of users. Users can be categorized into various groups, while groups are a set of multiple users.
It isn’t easy to manage the privileges such as security and permission rights among different users. Group command makes it easy to manage them at a group level.
Give the username as input; it will return the member’s name of primary and secondary groups. If no names are specified, it will print the currently running user information.
Syntax:
Syntax of “group” command would be like this:
$ group [option] [username]
How to use the “group” command:
Open the terminal, type “groups” to print the list of all groups that are currently logged in:
Adding username as input:
Provide the username as an argument to get a list of all groups from which a particular user belongs, a username of my Linux device is “aqsa”:
Getting User id:
Use the “id” command to display the information about a user and its groups. The command will show the primary and secondary groups; primary shows the user and group id while secondary shows the username:
Displaying usernames:
Use a combination of “-n” and “G” options to print usernames of all groups instead of user ids:
Displaying group details:
Two ways to display the group’s details:
- /etc/groups
- “getent” command
Use the below-mentioned command to get the list of all Linux groups:
The “getent” command shows entries from specified databases, which can be used to get a list of all groups:
To get the information of any particular group, pass “username” as an argument:
If no output comes, it means the group does not exist.
Getting help information:
To print help information, type the “–help” command in a terminal. It gives a brief description and the related links of the “groups” command.
Checking the version:
To check the version of the “groups” command in Linux, use the “version” command:
Conclusion:
A “group” in Linux is a collection of users. The “groups” command lists all the groups and their details in the terminal. Groups make it simple to handle users who have similar security and access rights. We can also use the “/etc/group” and “getent” commands to display a list of groups. We have learned what the “groups” command is and the functionality of its different options.