Linux / Unix: groups Command Examples

Linux / Unix groups command

I am a new Linux and Unix system user. How do I list the groups a user named foo belongs to? How can I display display the groups a user is in on Linux or Unix-like systems?

You need to use the groups command to show the groups a user belongs to on Linux or Unix shell prompt.[donotprint]

groups command details
DescriptionFind user's group memberships
Root privilegesNo
Est. reading time1m
Table of contents


List a user’s group memberships.


The basic syntax is as follows:

groups [UserNameHere] groups --help
groups --version

groups command examples

To simply show a user’s group memberships for the current user, type:
$ groups
Sample outputs:

Animated gif 01: groups command in action

Animated gif 01: groups command in action

In this example, twelev groups are output: staff, everyone, localaccounts, _appserverusr, admin, _appserveradm, _lpadmin, _appstore, _lpoperator, _developer,, and You can easily count total group with the following wc command:
$ groups | wc -w
Sample outputs:


Recommend alternative to groups command

The groups command has been obsoleted by the id command. You need to use the following command which is equivalent to id -Gn:
$ id -Gn
$ id -Gn root

Sample outputs:

wheel daemon kmem sys tty operator procview procmod everyone staff certusers localaccounts admin _appstore _lpadmin _lpoperator _developer
See also
  • /etc/group file.
  • groups(1) Linux/Unix command man page
  • Man pages – group(5)

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • kmayebale Oct 3, 2015 @ 5:57

    groups works fine as well

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum