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 01-31-2014, 10:12 AM   #1
LQ Newbie
Registered: Dec 2013
Posts: 4

Rep: Reputation: Disabled
how to count the number of users in a group?

Hello People,

I used this command ypcat group |grep zebra1 which list all the users in zebra1 group but I want to know exaclty how many users are in the group. Is there any commands to list the number of users?

Old 01-31-2014, 10:48 AM   #2
Registered: Mar 2013
Distribution: Debian
Posts: 42

Rep: Reputation: Disabled
ypcat group |grep zebra1 | wc -l

wc -l will count the number of lines.
Old 01-31-2014, 10:49 AM   #3
Registered: Feb 2006
Posts: 47

Rep: Reputation: 29
Checkout the man pages for wc - that should do it.

ypcat group |grep zebra1 | wc -l
Hope this helps
Old 01-31-2014, 11:28 AM   #4
LQ Newbie
Registered: Dec 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Try that wc -l earlier, it didn't work
Old 01-31-2014, 11:50 AM   #5
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Originally Posted by bonnydeal View Post
Checkout the man pages for wc - that should do it.

ypcat group |grep zebra1 | wc -l
Note that -l option counts lines, not words or columns. Since output of ypcat group... command is one liner, so there's no point of using -l option, but instead there should be used -w (it stands for words count, check man page of wc). However, you should try some utility like awk to count all users in a group. Just give it a try:
~$ awk -F"," '/zebra1/ {gsub(","," ",$0); print $0}' /etc/group | wc -w

Last edited by shivaa; 01-31-2014 at 11:52 AM.
Old 01-31-2014, 05:49 PM   #6
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,696

Rep: Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261
Also - the list of users in the group is not complete. It doesn't necessarily include users with that group as the default group specified in the passwd map.

What makes it worse, is that there CAN be overlap between the two lists. Users can be entered in the group map as well as having it as their default group.


linux, unix

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
[SOLVED] how to count number sessions of users? wwinay Linux - General 11 02-28-2013 02:40 AM
count number of used ports mnchur Linux - General 2 02-10-2009 02:11 PM
how to count the number of occurrences of a process beeblequix Linux - General 3 09-18-2006 04:17 PM
number of users in a group cookie_ie Programming 7 03-24-2005 03:43 PM

All times are GMT -5. The time now is 10:00 PM.

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