Freebsd – Get list of users in a group in FreeBSD

freebsdgroupsusers

How to get a list of usernames assigned to a group in FreeBSD 11.1?

This Question asks for a list of users or a list of groups.

This Question asks for users who happen to be members of multiple specific groups.

➥ But how to ask simply for a list of users currently assigned to a single specific group, such wheel?

I prefer a solution in a single command if possible. But if not feasible, a script would be useful and educational.

Best Answer

You can select users with specific group from list of all users given by pw utility:

pw usershow -P -a | grep groupname

Result will be something like:

Login Name: username1     #1024         Group: groupname          #1002
Login Name: username2     #1025         Group: groupname          #1002