Beginners Guide for Groups Command in Linux

Linux TLDR
Last Updated:
Reading time: 2 minutes

The Linux system consists of multiple users and groups; there might be a large number of users in your system that can be easily managed by adding them to a specific group.

After adding them, you can easily assign different permissions and policies to that specific group of users and remove them when they are not required.

A good example is sudo. If you are not part of the sudo group, you will not be able to perform any system level changes similar to that.

You might be part of many other groups that you can list using the groups command.

Tutorial Details

Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Internet RequiredNo

Syntax of the Groups Command

The β€œgroups” command takes one argument asking for a username, as shown.

$ groups [USERNAME]

Although you can specify multiple usernames by using the space as a separator.

Listing All Groups to Which a Specified User Belongs

Specify the β€œusername” with the groups command to list all the groups to which the specified user belongs.

$ groups linuxtldr


Listing user linked to which group using groups command

If you do not specify the β€œusernameβ€œ, the groups command will show the result for the currently logged-in user.

Display the Current User’s UID, GID, and Groups to Which They Belong

The id command is used to display information about the current user’s ID (UID), group ID (GID), and groups to which they belong.

It is followed by the type with an β€œ=” sign, then the user or group ID, and the username.

$ id


Listing user linked to which group using groups command

Getting a Username Without a User ID

The β€œ-n” and β€œ-G” flags can be used with the β€œid” command to display only the name instead of a number.

$ id -nG


Printing only the group label using id command

Listing All Groups in Your System

Whenever you create a new group or record for existing groups is recorded at β€œ/etc/group” file that you can read using the cat command.

$ cat /etc/group


Checking all group by reading the content of etc group file

Alternatively, you can use the getent command to get the same output as above.

$ getent group


Checking all group using the getent command

That was the end of the article.

If you have any thoughts, feel free to exchange them in the comment section.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.