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

ADVERTISEMENTS

Linux Show All Members of a Group Commands

  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 as follows:

$ grep 'grpup-name-here' /etc/group

$ grep 'ftponly' /etc/group

$ grep -i --color 'ftponly' /etc/group

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

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

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

#linux

Linux Show All Members of a Group Command - nixCraft
2.05 GEEK