Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
Depends on where you look. I've definitely seen that spelling before. To be technically correct, *n*x would be most accurate... –  Joshua Nurczyk Jan 11 '10 at 18:27

2 Answers 2

up vote 4 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
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.