Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-16-2011, 11:12 AM   #1
LQ Newbie
Registered: Mar 2011
Location: Highlands Ranch, Colorado
Posts: 2

Rep: Reputation: 0
Question How to list group members and show user id and full name

After finding this to show all users on a system I was wondering what modification would work to just show members of a given group, show their user id and full name?

awk -F":" '{ print "UserName: " $1 "\tUserID:" $3 "\tFullName: " $5 }' /etc/passwd
Old 12-16-2011, 12:29 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,986
Blog Entries: 14

Rep: Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187Reputation: 1187
/etc/passwd contains the primary group of the user (the one specified with -g in useradd). If, however, the user is a member of secondary groups (specified with -G in useradd/usermod) then your script wouldn't find them. You'd need to add info to get info from /etc/group as well.

So your command would need to be modified to print the group field "$4" rather than the user field "$3" for primary:
awk -F":" '{ print "UserName: " $1 "\tUserID:" $4 "\tFullName: " $5 }' /etc/passwd

However as noted that wouldn't get secondary groups. You'd have to script that. The command "groups <username> will show you in which group names the specified user is a member. Also the "id <username>" will show you in which group numbers the specified user is a member.

You'd have to make a modified script that got user's from /etc/passwd then got the group information for them using your choice of groups or id.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to list all members of a group bg108 Linux - Newbie 12 11-24-2013 03:26 AM
How to list user in Linux box, add an user to a group! steady_lfcfan Linux - Newbie 12 01-27-2013 01:14 PM
listing the members of a group bondoq Linux - Server 3 02-25-2007 05:10 PM
List files owned by user/group guideweb Linux - General 1 09-18-2004 08:18 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:20 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration