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.
You can select users with specific group from list of all users given by
pw
utility:Result will be something like:
Disregarding system scripts like
getent
, users can be in a group in two ways: either it is their principal group, defined in /etc/passwd, or they have it as a secondary group in /etc/groups.Should do it nicely.
awk
would probably look nicer...https://www.cyberciti.biz/faq/linux-list-all-members-of-a-group/ thread show multiple ways of doing this. I personally prefer members method. but the method below is native and works well.
The proper way to show all users in a certain group under FreeBSD is: