Linux / Unix: groups Command Examples

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
Description Find user’s group memberships
Root privileges No
Estimated completion time 1m


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

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)
Category List of Unix and Linux commands
File Management cat
Network Utilities dighostip
Package Manager apkapt
Processes Management bgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searching whereiswhich
User Information idgroupslastlastcommlognameuserswwhowhoamilid/libuser-lidmembers

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts