count amount of accounts?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers count amount of accounts?
# 1  
Old 10-31-2008
count amount of accounts?

Hi,

I am relatively new to Unix and trying to understand as much as I can.
I would like to know if it's possible to count the total number of Unix accounts? If so, can the count be done from any working directory or does it have to be specific to where the accounts are based?

Thanks!
# 2  
Old 10-31-2008
The /etc/passwd file keeps track of the accounts. One line per account. the wc -l command counts lines in a file.
Code:
wc -l /etc/passwd

# 3  
Old 11-01-2008
but /etc/passwd also contains system account details. in linux user account id starts from 500 onwards. You can grep/search for account from 500 onwards.

- nilesh
# 4  
Old 11-02-2008
use this script to know the users that have user ID's between 500 and 1000 . If you think there are more number of users, you can increase the number.

#!/bin/bash

count=0;

OIFS=$IFS;
IFS=:


while read line
do
res=`echo $line | awk '{print $3}'`;
if [ $res -ge 500 ] && [ $res -lt 1000 ]
then
count=`expr $count + 1 `
fi
done < /etc/passwd
echo $count

IFS=$OIFS

exit 0
# 5  
Old 11-02-2008
Or a short version of the above code:
Code:
awk -F: '{if ($3 >= 1000) x++} END {print x}' /etc/passwd

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Max amount of parameter

Hello everyone, I am trying to write a ksh script to accept user amount of parameters. so far I have written the following but, when I run the script it gives me the "i" back instead of the parameter's value. can anyone please tell me what I'm doing wrong. Thank you in advance:):) ... (9 Replies)
Discussion started by: Joveini
9 Replies

2. UNIX for Dummies Questions & Answers

Sum of an amount columns

Hi Friends.. I'm completely new to Unix and I need to write a program / script to sum amount columns in a .DAT file by using a configuration file to read the position of the columns. Could someone pls. help me on how to proceed? I've never written a program to read a configuration file and... (3 Replies)
Discussion started by: davinds
3 Replies

3. Solaris

Amount of LUNs used for zpool

Hi folks, is there any rule or best practise for amount of LUNs user for zpool construction (from view of performance etc.)?? THX (4 Replies)
Discussion started by: brusell
4 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Count amount of times of appearing of character before a word?

Hello Is there a way to calculate how many times a particular symbol appeared in a string before a particular word. Desktop/Myfiles/pet/dog/puppy So, I want to count number of occurence of"/" in this directory before the word dog lets say. Cheers, Bob (3 Replies)
Discussion started by: FUTURE_EINSTEIN
3 Replies

5. UNIX for Dummies Questions & Answers

Is it possible to grep a certain amount of characters?

I have a file similar to the following filler filler filler car 6 mazda filler filler filler filler car civic honda car rav 4 toyota filler filler If i do a "grep -i car file.txt" the output would be car 6 mazda car civic honda car rav 4 toyota however, i want to have the... (4 Replies)
Discussion started by: jl487
4 Replies

6. AIX

Fastest way to count big amount of files in sub directory

Hi, what happened is we want to count all the files in a directory and inside this directory got many folders and so take long time to count it. Already run for about few minutes but still not done. The command we use to count is find . -type f | wc -l Just wondering if there is any other... (9 Replies)
Discussion started by: ngaisteve1
9 Replies

7. Shell Programming and Scripting

d. Write a shell script to count the number of accounts which belong to particular primary

guys, I am new shelll scripting.. this a question on passt exam paper, I was trying to solve it , I can not. the question is as follow? a. Write a shell script to count the number of accounts which belong to particular primary group in a standard UNIX system which uses local... (1 Reply)
Discussion started by: gurmad
1 Replies

8. UNIX for Dummies Questions & Answers

amount of memory in my server

Hi all, is there any command that i can execute to find out the size of the harddisk and RAM on my server? Because i am not the SA, i do not have access to such infomation. (2 Replies)
Discussion started by: new2ss
2 Replies

9. UNIX for Dummies Questions & Answers

How to get amount of memory installed.

Hi! I'm not a UNIX fanatic but I like using it for the Oracle database since it's not stable in the Windows NT environment (what is?). Problem: Is there any command to show me the amount of installed physical-memory in the machine? Is there some other way to show the processes which uses... (4 Replies)
Discussion started by: elgholm
4 Replies
Login or Register to Ask a Question