How to list what users are in a group

Chris Adams cmadams at hiwaay.net
Wed Apr 21 14:16:13 UTC 2010


Once upon a time, Karl-Olov Serrander <m11172 at abc.se> said:
> On Wed, 21 Apr 2010, Natxo Asenjo wrote:
> > On Wed, Apr 21, 2010 at 12:39 AM, David Bartmess <dingodave at edingo.net> wrote:
> >> This is a basic linux question, but how do I find out what users are
> >> included in a given group?
> >>
> >> Thanks!
> >
> > getent group <groupname> should do the trick.
> 
> But that doeas not show users which has groupname as the primary group.

No, for that you have to list all users and look at the primary group
field.

getent passwd | grep "^[^:]*:[^:]*:[^:]*:$(getent group <groupname> | cut -d: -f3):"

Primary/aux groups in Unix are set up in a less-than-efficient way for
searching.
-- 
Chris Adams <cmadams at hiwaay.net>
Systems and Network Administrator - HiWAAY Internet Services
I don't speak for anybody but myself - that's enough trouble.


More information about the users mailing list