Linux: members Command Examples

members command

I am a new Linux and Unix system user. How do I list the members of a group on Linux or Unix-like systems?

There are various ways to get this information on both Linux and Unix-like system.[donotprint]

members command details
DescriptionShow members of a group
CategoryN/A
DifficultyEasy
Root privilegesNo
Estimated completion time2m
Contents
[/donotprint]

ADVERTISEMENTS

Purpose

Outputs members of a group.

Syntax

The basic syntax is as follows:

members groupNameHere

OR

members [options] groupNameHere

members command examples

Buy default members command display all group members on one line. Open the Terminal application and type the following command to display members of ‘webmaster’ group:
$ members webmaster
Sample outputs:

Animated gif 01: Displaying a list of members of a group called webmaster

Animated gif 01: Displaying a list of members of a group called webmaster

In this example, six users are output: webadmin, raj, vivek, archana, sai, and sayali. You can count total users in a group called members using wc command:
$ members webmaster | wc -w
Sample outputs:

6

Display only primary group members

Pass the -p option:
$ members -p webmaster

Display only secondary group members

Pass the -s option:
$ members -s webmaster

Query /etc/group file

Use the following grep command:

grep '^webmaster' /etc/group

Use getent command to query groups

Use the following getent command to query group database (such as file or NIS based group database):
$ getent group | grep '^webmaster'

See also
  • /etc/group file.
  • members(1) Linux/Unix command man page
  • Man pages – grep(1)
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Package Managerapkapt
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searchingwhereiswhich
User Informationidgroupslastlastcommlognameuserswwhowhoamilid/libuser-lidmembers

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.