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.

Terminal window
groups [options] [username]
OptionDescription
-h, —helpDisplay help information
-v, —versionDisplay version information
ParameterDescription
usernameThe username to display groups for
Terminal window
groups username

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

Terminal window
groups

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

Terminal window
sudo groupadd newgroup

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

Terminal window
sudo usermod -aG groupname username

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

Terminal window
sudo deluser username groupname

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

Terminal window
getent group groupname

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

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?

Section titled “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?

Section titled “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?

Section titled “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?

Section titled “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?

Section titled “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?

Section titled “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
  • Display the groups to which a user belongs.