Linux: Finding all the members of a group

By Druss , 17 May, 2011

Finding all the members of a group is an occasional requirement and while there are a number of ways to do this by parsing the /etc/group and /etc/password files, Debian/Ubuntu come with a simpler solution that performs all this skulduggery for you. This is the members function that can simply be installed using sudo apt-get install members . Once this is done, members of a group named foo can be listed using:
members foo.

The function also supports a few options to differentiate between primary and secondary group members. The man page is as follows:

MEMBERS(1)

NAME
members - outputs members of a group

SYNOPSIS
members groupname

DESCRIPTION
This manual page documents briefly the members commands. This manual page was written for the Debian GNU/Linux distribution.

members is a program that sends a space-separated list of secondary member names to its standard output.

OPTIONS
The programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below.

-a, --all
Show all group members on one line. This is the default.

-p, --primary
Show only primary group members.

-s, --secondary
Show only secondary group members.

-t, --two-lines
Send two lines to standard output. First line is primary members, second line is secondary members. NOTE: This always displays two lines, even if there are no members at all.

-h, --help
Show summary of options.

I'm not sure if this package is available for other distributions. It probably is.

Hope this helps.

All times are UTC. All content licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.