≡ Menu

Linux: Show All Members of a Group

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)

Sysadmin because even developers need heroes!!!

Share this tutorial on:
{ 11 comments… add one }
  • steven werner July 7, 2014, 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

    • C Yates November 11, 2014, 9:30 am

      “thrid” command?

      • Anonymous Coward May 12, 2015, 9:08 pm

        Yes, it’s right after the sceond command.

  • Danilo Clemente October 21, 2014, 5:08 pm

    You might prefer use the getent since the group database could be on LDAP, NIS e etc:
    $ getent group ftponly

  • nitesh February 6, 2015, 8:53 am

    show group member
    groupmems -g (group name) -l

  • bob January 20, 2016, 2:57 pm

    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

  • Arpad June 30, 2016, 2:17 am

    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

    • C July 6, 2016, 7:57 pm

      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!

  • vivak July 7, 2016, 7:12 am

    how can i print alphates in matrix
    a b c d e f
    g h i j k l m
    n o p q r s

    this way please help me

  • David November 4, 2016, 6:32 pm

    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.

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , ,