Linux: Show All Members of a Group

by on January 29, 2013 · 1 comment· LAST UPDATED January 29, 2014

in , , , , , ,

I am a new Linux user and created couple of groups on server. I need to find out all members of a group called "ftponly". How do I list all members of a group on Linux or Unix-like systems?

The /etc/group file is a text file that defines the groups on the Linux and Unix based systems. You can simply query this file to find and list all members of a group.

    Tutorial details
    DifficultyEasy (rss)
    Root privilegesYes
    RequirementsNone
    Estimated completion time1m

  1. /etc/group file - User group file
  2. members command - List members of a group
  3. lid command - List user's groups or group's users

Linux: List all members of a group using /etc/group file

Use grep command as follows:
$ grep 'grpup-name-here' /etc/group
$ grep 'ftponly' /etc/group
$ grep -i color 'ftponly' /etc/group

Sample outputs:

ftponly:x:1001:raj,vivek,archana,sai,sayali

To get just a list of all members of a group called ftponly, type:

 
awk -F':' '/ftponly/{print $4}' /etc/group
 

Linux: List all members of a group using members command

Warning: members command is not installed on most distros. Use yum command or apt-get command to install the same:

sudo apt-get install members

To outputs members of a group called ftponly, enter:
$ members ftponly
Sample outputs:

Fig. 01: members command in action to list members in a group

Fig. 01: members command in action to list members in a group


In this example the members command displays a space-separated list of group member names on screen.

Linux: How to list all users in a Linux group using lid command

You can displays information about groups containing user name, or users contained in group name using lid command as follows.

Warning: lid command is not installed on most distros. Use yum command or apt-get command to install the same:

sudo apt-get install libuser

To see users contained in group named 'ftponly':

# lid -g ftponly
Sample outputs:

 raj(uid=1001)
 vivek(uid=1002)
 archana(uid=1003)
 sai(uid=1004)
 sayali(uid=1005)

To show information about groups containing user named 'nixcraft':

# lid nixcraft
Sample outputs:

 adm(gid=4)
 cdrom(gid=24)
 sudo(gid=27)
 dip(gid=30)
 plugdev(gid=46)
 lpadmin(gid=109)
 nixcraft(gid=1000)
 sambashare(gid=124)
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 1 comment… read it below or add one }

1 steven werner July 7, 2014 at 5:59 pm

thrid command at the top has a typo

$ grep -i color ‘ftponly’ /etc/group

missing (–)color

$ grep -i –color ‘ftponly’ /etc/group

Might confuse newbies

Reply

Leave a Comment

Tagged as: , , , ,

Previous Faq:

Next Faq: