How to Run ‘groups’ command in Linux

10

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”:

How to Run ‘groups’ command in Linux 1620471365 196 How to Run    groups command in Linux

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:

How to Run ‘groups’ command in Linux 1620471366 346 How to Run    groups command in Linux

Displaying usernames:

Use a combination of “-n” and “G” options to print usernames of all groups instead of user ids:

How to Run ‘groups’ command in Linux 1620471366 776 How to Run    groups command in Linux

Displaying group details:

Two ways to display the group’s details:

  1. /etc/groups
  2. “getent” command

Use the below-mentioned command to get the list of all Linux groups:

How to Run ‘groups’ command in Linux 1620471367 910 How to Run    groups command in Linux

The “getent” command shows entries from specified databases, which can be used to get a list of all groups:

How to Run ‘groups’ command in Linux 1620471367 500 How to Run    groups command in Linux

To get the information of any particular group, pass “username” as an argument:

How to Run ‘groups’ command in Linux 1620471368 265 How to Run    groups command in Linux

If no output comes, it means the group does not exist.

How to Run ‘groups’ command in Linux 1620471368 142 How to Run    groups command in Linux

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.

How to Run ‘groups’ command in Linux 1620471369 859 How to Run    groups command in Linux

Checking the version:

To check the version of the “groups” command in Linux, use the “version” command:

How to Run ‘groups’ command in Linux 1620471370 365 How to Run    groups command in Linux

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.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More