LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-31-2014, 11:12 AM   #1
Linuxlearner122
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?

Thanks,
 
Old 01-31-2014, 11:48 AM   #2
r41d3n
Member
 
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, 11:49 AM   #3
bonnydeal
Member
 
Registered: Feb 2006
Posts: 47

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


Code:
ypcat group |grep zebra1 | wc -l
Hope this helps
 
Old 01-31-2014, 12:28 PM   #4
Linuxlearner122
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, 12:50 PM   #5
shivaa
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
Quote:
Originally Posted by bonnydeal View Post
Checkout the man pages for wc - that should do it.


Code:
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:
Code:
~$ awk -F"," '/zebra1/ {gsub(","," ",$0); print $0}' /etc/group | wc -w

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

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
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.
 
  


Reply

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


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

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