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
There are two types of groups in Linux:
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
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
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 to list members in a group
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