Linux / Unix: groups Command Examples

by on January 25, 2012 · 0 comments· LAST UPDATED January 25, 2014

in , ,

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.

groups command details
DescriptionFind user's group memberships
Category
Difficulty
Root privilegesNo
Estimated completion time1m
Contents

Purpose

List a user's group memberships.

Syntax

The basic syntax is as follows:

groups
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, com.apple.access_screensharing, and com.apple.access_ssh. You can easily count total group with the following wc command:
$ groups | wc -w
Sample outputs:

      12

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 com.apple.access_screensharing com.apple.access_ssh
See also
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searchingwhereiswhich
User Informationgroupsidlastlastcommlognameuserswwhowhoamilidmembers

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: ,

Previous Faq:

Next Faq: