Skip to content

groups Linux command

The Linux groups command allows users to manage group information on a system. It displays the groups a user belongs to, including primary and supplementary groups. By simply typing ‘groups’ followed by a username, you can easily view all the groups associated with that specific user. Additionally, administrators can add or remove users from groups using this command, enabling efficient management of user permissions and access rights.

groups Syntax:

Terminal window
groups [options] [username]

Options:

OptionDescription
-h, —helpDisplay help information
-v, —versionDisplay version information

Parameters:

ParameterDescription
usernameThe username to display groups for

groups bash Examples:

Display the groups a user belongs to

Terminal window
groups username

This command will show the groups that the specified user “username” is a member of.

Display all groups on the system

Terminal window
groups

Running this command without any arguments will display all the groups that the current user is a member of.

Create a new group

Terminal window
sudo groupadd newgroup

It creates a new group called “newgroup” on the system.

Add a user to a group

Terminal window
sudo usermod -aG groupname username

This adds the user “username” to the group “groupname” without removing the user from their existing groups.

Remove a user from a group

Terminal window
sudo deluser username groupname

This removes the user “username” from the group “groupname”.

Check members of a particular group

Terminal window
getent group groupname

This command shows the list of users who are members of the group “groupname”.

How do I use groups in Linux?

To use the groups command in Linux, execute the following command:

Terminal window
groups

How can I display all groups a user belongs to in Linux?

To display all groups a user belongs to in Linux using the groups command, use the following syntax:

Terminal window
groups username

How do I show the group ID instead of the group name with the groups command?

To display the group ID instead of the group name when using the groups command in Linux, use the -g option like this:

Terminal window
groups -g

How can I display groups in a comma-separated list with the groups command?

To display groups in a comma-separated list using the groups command in Linux, include the -c option in your command:

Terminal window
groups -c

How do I display the effective group ID of the current user with groups command?

To display the effective group ID of the current user using the groups command in Linux, use the -e option like this:

Terminal window
groups -e

How can I see additional information about the groups command in Linux?

To see additional information about the groups command in Linux, refer to its man page by executing the following command:

Terminal window
man groups

How do I display the version information for the groups command?

To display the version information for the groups command in Linux, you can use the --version option like this:

Terminal window
groups --version

Applications of the groups command

  • Display the groups to which a user belongs.