LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 07-08-2012, 03:34 AM   #1
daud795
LQ Newbie
 
Registered: Apr 2012
Posts: 3

Rep: Reputation: Disabled
how to check how many user


i want to know through which command i can check how many users i have created so far

Last edited by daud795; 07-08-2012 at 03:36 AM.
 
Old 07-08-2012, 04:53 AM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Posts: 222

Rep: Reputation: 62
If we assume that all users have their home directories in /home

Code:
grep '/home' /etc/passwd -c





Quote:
Originally Posted by daud795 View Post
i want to know through which command i can check how many users i have created so far
 
Old 07-08-2012, 01:23 PM   #3
one_with_linux
LQ Newbie
 
Registered: Jul 2012
Location: Utah
Distribution: gentoo, ubuntu, mint, whatever is new
Posts: 8

Rep: Reputation: Disabled
this shell script might work...
Code:
#!/bin/bash
id=1000
numuser=0;
while :
do
check=`cat /etc/passwd | grep $id`
if [[ -z "$check" ]]
then 
echo -n "there are "
echo -n $numuser
echo " users"
break
else
((id++))
((numuser++))
fi
done
i just wrote this and it has only been tested on my system so it might not work....
also you might try
Code:
grep -c "" count `awk -F: '$6 ~ /\/home/ && $3 >= 500 {print $1}' /etc/passwd > count`
but that will leave a count file behind
Code:
rm count
 
Old 07-08-2012, 07:01 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
More generically, just
Code:
cat /etc/passwd
The thing that post#3 is hinting at is that some distros start non-root accts at uid 500, some at 1000, hence if you don't know which, I'd go with post#2 (assuming /home) or just use mine to start with .. find out what the data looks like before you start using short cuts.
Its not a large file unless you've got eg >100 users.
 
Old 07-08-2012, 07:10 PM   #5
ceh383
Member
 
Registered: May 2003
Location: The Left coast, USA
Distribution: Slackware_64 13.37
Posts: 183

Rep: Reputation: 21
if all you want to know is user accounts....presuming all users directories are in /home...then...

Code:
ls -l /home
 
  


Reply


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
check user password toredo Programming 5 12-08-2009 05:12 AM
How to check if user has mailbox ? dlugasx Linux - Server 1 11-13-2009 02:01 AM
C user function to check whether a given user has access permission to a file iamjayanth Linux - Software 2 10-07-2009 08:16 AM
super user privileges check for a normal user in bash script freeindy Programming 2 08-01-2008 07:08 AM
User can't check email? LWillmann Linux - Server 3 08-15-2007 09:29 AM


All times are GMT -5. The time now is 06:10 AM.

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