LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-19-2008, 06:37 AM   #1
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124
Blog Entries: 2

Rep: Reputation: 15
how many users / home capacity over command line


hi everyone,
i want to learn how to do 2 things over command line. first one is,how many users are registered on current operating system. the second one how to learn the capacity of the home directories of these users..

thanks..
 
Old 02-19-2008, 06:44 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
the basic user database is /etc/passwd - 'wc -l /etc/passwd' would give you the total users but not all are human. As far as the disk usage, du will help there. Also, if you're just interested in # of users with home directories, count 'em, again with wc. If you want something more precise, be more precise.
 
Old 02-19-2008, 07:08 AM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,923
Blog Entries: 44

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
Hi,
Quote:
Originally Posted by laucian View Post
hi everyone,
i want to learn how to do 2 things over command line. first one is,how many users are registered on current operating system. the second one how to learn the capacity of the home directories of these users..

thanks..
I would like to add that you could look at 'Linux Command Guide' and 'Linux Newbie Admin Guide' for some good guidance.

These links and others can be found at 'Slackware-Links' .
 
Old 02-19-2008, 07:14 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Here is a short awk program that will extract regular users from /etc/passwd:

Code:
#!/bin/bash

# Get the maximum and minimum values for user UIDs
UID_MIN=$(awk '/^UID_MIN/ {print $2}' /etc/login.defs )
UID_MAX=$(awk '/^UID_MAX/ {print $2}' /etc/login.defs )

# Print out usernames with a UID between UID_MIN and UID_MAX
awk 'BEGIN {FS=":"} ($3>='$UID_MIN') && ($3<='$UID_MAX') {print $1}' /etc/passwd
Similarily:
Code:
#!/bin/bash

# Get the maximum and minimum values for user UIDs
UID_MIN=$(awk '/^UID_MIN/ {print $2}' /etc/login.defs )
UID_MAX=$(awk '/^UID_MAX/ {print $2}' /etc/login.defs )

# print the number of regular users

awk 'BEGIN {FS=":"} ($3>='$UID_MIN')&&($3<='$UID_MAX'){ num_users++ } END { print num_users }' /etc/passwd
I think that /etc/login.defs is standard. Different distro's use different ranges for the UIDs of regular users. Mandrake and Fedora Core start at 500. SuSE starts at 1000. There is a user called nobody that has a UID of 65534.

getent passwd nobody
nobody:x:65534:65533:nobody:/var/lib/nobody:/bin/bash

Last edited by jschiwal; 02-19-2008 at 07:20 AM.
 
Old 02-20-2008, 08:06 AM   #5
laucian
Member
 
Registered: Oct 2005
Distribution: Ubuntu 9.04
Posts: 124

Original Poster
Blog Entries: 2

Rep: Reputation: 15
thanks for all your help,
i will again write some feedback...

i used the dh -f command the get the harddisk overview..

Code:
mfc-falter:~ # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6              20G  3.8G   15G  21% /
udev                  439M  100K  439M   1% /dev
/dev/sda7              89G  527M   84G   1% /home
/dev/sda1             5.4G   45M  5.4G   1% /windows/C
/dev/sda2             116G   46G   71G  40% /windows/D
and for the single directories i used du -h command..-h is for the human readable format..

to get all registered "human" users, i just opened /etc/passwd file with less command and searched for /home/ directory..the i counted them..as i had maximum 7-8 users on a single machine, counting them manually wasn't really a big problem.

anything else, any corrections?
 
  


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
Local users cannot send mail from command line or cronjobs jonken Linux - Server 3 01-10-2008 03:29 PM
seti@home command line jak2586 Linux - Newbie 5 10-02-2006 08:56 PM
change user home directory from command line cccc Debian 1 03-23-2006 05:07 PM
Adding users via command Line AmdMhz Linux - Software 4 10-31-2004 01:29 PM
How to get list of system users from command line? tictocdoc Linux - General 3 03-12-2004 03:06 PM

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

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