Command to List *nix Group Members?

What's the command to figure out who the members are of a *nix group?

2

2 Answers

depending on the environment, for secondary groups here are some options.:

"getent group | grep ^groupname:" (getent - get entries from administrative database)

"ypcat group | grep ^groupname:" (ypcat - print values of all keys in a NIS database)

"grep ^groupname: /etc/group" (/etc/group is the local group file)

and if you just want the name of the group and the users add "| cut -d: -f1,4" to the end of the string (example: grep ^groupname: /etc/group | cut -d: -f1,4)

The primary group id is listed in the passwd file entry for each user, so the user's primary groups won't show up in the output of any of the commands listed above. You could "grep ^groupname: /etc/group | cut -d: -f1,3" to get the groupid number, then "grep :groupidnumber: /etc/passwd | cut -d: -f1" to get the user's account name.

1
grep ^<groupname>: /etc/group

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like