LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 10: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, 10: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, 10: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, 11:28 AM   #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, 11:50 AM   #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 11:52 AM.
 
Old 01-31-2014, 05:49 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:20 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
Open Source Consulting | Domain Registration