Linux Show All Members of a Group Command

I am a new Linux user and created a couple of groups on the 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.

Linux Show All Members of a Group Commands

    Tutorial details
    Difficulty level Easy
    Root privileges Yes
    Requirements None
    Est. reading time 1m
  1. /etc/group file – User group file
  2. members command – List members of a group
  3. lid command (or libuser-lid on newer Linux distros) – List user’s groups or group’s users

There are two types of groups in Linux:

  • Primary group – is the main group that is associated with user account. Each user is a member of exactly one primary group.
  • Secondary group – used to provide additional rights to user. For example, access to the dvd/cdrom drive can be granted with help of cdrom group.

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

Use the grep command or cat command/more command as follows:
$ grep 'grpup-name-here' /etc/group
$ grep 'ftponly' /etc/group
$ cat /etc/group
$ less /etc/group
$ grep -i --color 'ftponly' /etc/group


We can also type the compgen command or getend command to list all group names on Linux:
$ compgen -g
$ getent group

To get just a list of all members of a group called ftponly, type the following awk command:

awk -F':' '/ftponly/{print $4}' /etc/group
# list all members of sudo group in linux #
awk -F':' '/sudo/{print $4}' /etc/group

Display group memberships for each Linux user

Want to see group memberships for each given USERNAME under Linux? The syntax is as follows for the groups command:
groups {USERNAME}
groups vivek

The following outputs indicates that the user named ‘vivek’ is part of four groups including ‘vivek’ primary group:

vivek : vivek wheel lxd vboxusers

Linux List all members of a group using members command

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

To outputs members of a group called ftponly, enter:
$ members {GROUPNAME}
$ members ftponly

Fig. 01: members command in action on Linux show all members of a group command

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.

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
Please note that newer version of libuser renamed the lid command to libuser-lid. Thus, use it as follows:
$ sudo libuser-lid -g ftponly
Sample outputs:


To show information about groups containing user named ‘nixcraft’:

Use lid command or libuser-lid command on Linux to show all members of a group named nixcraft:
# lid nixcraft
$ sudo libuser-lid nixcraft
Sample outputs:


See lid command man page for more information.

How to list groups in Linux

To see all users, run less command/more command:
less /etc/group
more /etc/group
Another option is to type the following getent command:
getent group
For example, locate the members of a group with the name vboxusers, run:
getent group vboxusers
Sample outputs indicating vivek and raj users are part of vboxusers group:


Finally, you can use the id command to display real and effective user and group IDs:
id vivek
id -nG raj # show all group IDs for raj user
id -ng raj # show only effective group ID for raj user


Now you know how to use various Linux commands to show all members of a group. I suggest you read the man pages for more info by typing the following man command:
$ man libuser-lid
$ man members

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 17 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
17 comments… add one
  • steven werner Jul 7, 2014 @ 17:59

    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 Nov 11, 2014 @ 9:30

      “thrid” command?

      • Anonymous Coward May 12, 2015 @ 21:08

        Yes, it’s right after the sceond command.

  • Danilo Clemente Oct 21, 2014 @ 17:08

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

  • nitesh Feb 6, 2015 @ 8:53

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

  • bob Jan 20, 2016 @ 14:57

    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 Jun 30, 2016 @ 2:17

    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 Jul 6, 2016 @ 19:57

      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?)


      • cyp Apr 3, 2017 @ 8:12

        Yes, it shows only users that have the group as their primary group.

  • vivak Jul 7, 2016 @ 7:12

    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

    • Chano Jun 3, 2017 @ 8:57

      Try this:

      COUNTER=0; for i in {a..z}; do COUNTER=$((COUNTER+1)); echo -n "$i "; if ! (( COUNTER % 5)); then echo ""; fi ; done; echo ""

      It will make the following output:

      a b c d e
      f g h i j
      k l m n o
      p q r s t
      u v w x y
  • David Nov 4, 2016 @ 18:32


    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?


    • Chano Jun 3, 2017 @ 9:01

      Sysadmins are lazy, they don’t want to do a lot of work to complete a single task.

      But I suppose that writing a script that loops the groups file, line by line, searching for the separators, then looping the strings letter by letter, and printing the result, would be a quite complicated way to archive mostly the same result as using grep to get the line from the groups file.

      But maybe it’s just me that don’t have a need to scare people from using linux? :P

  • Leandro Dec 8, 2017 @ 17:10

    And how can i know who is the group’s administrator?

  • Michael Jones Aug 3, 2020 @ 18:09

    If I want to know all the members of a group, none of the commands will provide an answer. My solution is to run the id command on each user that has a home folder. A for loop seems to work the best for me:

    for u in $(ls /home); do id $u 2>/dev/null | grep ftponly; done

    This loop uses command substitution ‘ls /home’ to create a list of users that have home folders. Then I run the ‘id’ command on each user but if the id command has an error that output is sent to /dev/null by using the ‘2>’ redirect. For users where the ‘id’ command succeeds, that output is searched for the group name, in this case, ftponly.

  • Ben Feb 28, 2021 @ 16:17

    I wanted to list the all members of a group in Linux and this page on spot. Perfect tutorial.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum