Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I know I have existing groups and users but I'm not sure about their association. Is there an shell command I can use to list all users or all groups and a command to list all groups/users for a specified user/group?

So something like showusers would list all users, and showgroups -u thisuser would show all the groups that have thisuser in it.

share|improve this question
    
there is no such command. You need to script it by your self. –  Chris Feb 2 '12 at 13:25

2 Answers 2

up vote 5 down vote accepted

All users:

$ getent passwd

All groups:

$ getent group

All groups with a specific user:

$ getent group | grep username
share|improve this answer
for user in $(awk -F: '{print $1}' /etc/passwd); do groups $user; done

cat /etc/group | awk -F: '{print $1, $3, $4}' | while read group gid members; do
    members=$members,$(awk -F: "\$4 == $gid {print \",\" \$1}" /etc/passwd);
    echo "$group: $members" | sed 's/,,*/ /g';
done
share|improve this answer
    
While that would probably work, it seems a bit overly complicated, doesn't it, when there are perfectly good simple one-shot commands to do this? –  EEAA Jan 31 '12 at 4:41
    
It certainly wouldn't get anything that lives in a centralized repository. And that's definitely information that you'd want to see. –  Magellan Jan 31 '12 at 23:50

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.