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.

link|improve this question

there is no such command. You need to script it by your self. – Chris Feb 2 at 13:25
feedback

2 Answers

up vote 4 down vote accepted

All users:

$ getent passwd

All groups:

$ getent group

All groups with a specific user:

$ getent group | grep username
link|improve this answer
feedback
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
link|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? – ErikA Jan 31 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. – Adrian Jan 31 at 23:50
feedback

Your Answer

 
or
required, but never shown

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