LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Listing the members of a group (https://www.linuxquestions.org/questions/linux-general-1/listing-the-members-of-a-group-564167/)

armandino 06-24-2007 12:35 PM

Listing the members of a group
 
I'm running Fedora Core6.
What is the console command with which I can list all the users belonging to a certain group?

ilikejam 06-24-2007 12:47 PM

Hi.

Have a look in /etc/group , or run the following (this would be for the group 'dave'):
Code:

egrep '^dave' /etc/group | awk -F ':' '{print $4}'
Dave

Tinkster 06-24-2007 01:17 PM

Not lazy enough ... ;}
Code:

awk -F: '/^dave/ {print $4}' /etc/group

Cheers,
Tink

ilikejam 06-24-2007 02:40 PM

He he. Nice.

homey 06-24-2007 06:10 PM

Quote:

awk -F: '/^dave/ {print $4}' /etc/group
Unfortunately, that doesn't print the prime suspect, dave like this...
Code:

awk -F: '/^fred/{print $1","$4}' /etc/group

Tinkster 06-24-2007 06:43 PM

But then why would I want to print what I entered to begin with? I mean,
I know that I'm looking for group dave, and that there's (hopefully) only
going to be ONE group by that name ... of course, if I searched for adm
and there was an adm and an admin group I'd get them both ... hmmm ...


Oh well...

[edit]
Slightly more verbose but works around the issue described above ...
Use equality instead of a regex ;D


Code:

awk -F: '$1 == "nogroup" {print $4}' /etc/group
[/edit]


Cheers,
Tink


All times are GMT -5. The time now is 12:59 PM.