On Wed, May 9, 2012 at 2:07 AM, Murugan, Naresh Kumar <[email protected]> wrote: > Hi, > > Below commands will satisfy your requirement. > > List the users belong to the group > $ lid -g groupname| cut -f1 -d'(' > Or > $ egrep -i "^groupname" /etc/group|awk -F : '{print $4}' > > To print the primary group membership for a user: > $ id -g -n username > To print the secondary group membership for a user: > $ id -G -n username > > Regards, > M.Naresh Kumar > > -----Original Message----- > From: [email protected] [mailto:[email protected]] On > Behalf Of Kumar Appaiah > Sent: Wednesday, May 09, 2012 10:41 AM > To: [email protected] > Subject: Re: [Ilugc] How to list the users in a particular group > > On Tue, May 08, 2012 at 11:40:23AM -0400, Thanigai rajan wrote: >> I want to list the users belongs to particular group. >> >> For this I executed the command "grep -i groupname /etc/group" . This >> shows entries only when the user is added as secondary group. >> >> While searching the web , I found a command "members" with an option >> --secondary for Debian based distros. >> >> Is there any command same as "members" in redhat based distros ? > > This would be a classic use case for awk. Split fields by colons and > then display all the fourth fields where the first field is the group > name: > > awk 'BEGIN { FS = ":" } $1 ~ /powerdev/ { print $NF}' /etc/group > > I can help further if needed. > > Thanks. > > Kumar > -- > : > ####[ Linux One Stanza Tip (LOST) ]########################### > > Sub : Bothered by spam ? LOST #354 > > Spamassassin tries to figure out heuristically if a message is > spam. It does this by applying many rules to the message, and > assigning each rule a score (positive OR negative) ... If the > score goes above a predefined number, it's flagged as spam and > you can do the rest. [Visit: http://www.spamassassin.org]. > > ####[ajitabhpandey (at) users.sourceforge.net]################ > : > _______________________________________________ > ILUGC Mailing List: > http://www.ae.iitm.ac.in/mailman/listinfo/ilugc > > > Think green - keep it on the screen. > > This e-mail and any attachment is for authorised use by the intended > recipient(s) only. It may contain proprietary material, confidential > information and/or be subject to legal privilege. It should not be copied, > disclosed to, retained or used by, any other party. If you are not an > intended recipient then please promptly delete this e-mail and any attachment > and all copies and inform the sender. Thank you. > > > _______________________________________________ > ILUGC Mailing List: > http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Thanks Kumar & Naresh.for your reply. My requirement has satisfied with the command lid -u -g groupname , which is listing all the members of that group (no matter primary group or secondary group). 'Grep' ing the 4th field in /etc/groups will not list all the users of that particular group. Since it will give the list of members who are all engaged this group as secondary group . For Example : useradd -G 1234 user1 --- > is having the entry in 4th field of /etc/groups Whereas useradd -g 1234 user1 --> is not having the entry in 4th field of /etc/groups -- Thanks & Regards MThanigairajan The Most Certain Way To Succeed Is To Try One More Time -- By Edison _______________________________________________ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
