Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
It's normally spelled Un*x. – Josh K Jan 11 '10 at 17:11
Depends on where you look. I've definitely seen that spelling before. To be technically correct, nx would be most accurate... – Joshua Nurczyk Jan 11 '10 at 18:27
up vote 5 down vote accepted

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.

share|improve this answer
Or you can just do getent group <groupname> instead of the first three lines of greppage. – grawity Jan 11 '10 at 19:14
grep ^<groupname>: /etc/group
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .