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 07-08-2012, 02: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 02:36 AM.
 
Old 07-08-2012, 03:53 AM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 236

Rep: Reputation: 64
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, 12: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, 06:01 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 06:10 PM   #5
ceh383
Member
 
Registered: May 2003
Location: The Left coast, USA
Distribution: Slack_64 14.2
Posts: 226

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

Code:
ls -l /home
 
  


Reply



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

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

All times are GMT -5. The time now is 11:15 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