Linux: Show All Members of a Group

Posted on in Categories , , , , , , last updated May 13, 2015

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.

  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)

12 comment

  1. 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

  2. Please be aware that some of these commands will not show a user where their primary group is the one you are concerned with – as the primary group is listed in /etc/passwd

  3. Many of these require commands to be installed and as stated, don’t necessarily show a users’s primary group.

    This would work for that, though:
    grep group_name /etc/group |cut -d':' -f3 |xargs -Ix grep x /etc/passwd |cut -d ':' -f1

    1. does this command only show the users with group_name as their primary group? Or does it show all users with that group (either primary or secondary?)

      Thanks!

  4. Hi,

    I am finding that accomplishing simple tasks in Linux like getting a list of members of a group is not complicated or complex enough, which makes me feel inadequate because I cannot confound ‘n00bs’ with the arcane and difficult nature of Linux. Could anyone provide some more complicated ways of achieving these same results?

    Cheers.

Leave a Comment