LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how many users / home capacity over command line (https://www.linuxquestions.org/questions/linux-newbie-8/how-many-users-home-capacity-over-command-line-622217/)

laucian 02-19-2008 06:37 AM

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..

slakmagik 02-19-2008 06:44 AM

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.

onebuck 02-19-2008 07:08 AM

Hi,
Quote:

Originally Posted by laucian (Post 3062362)
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' .

jschiwal 02-19-2008 07:14 AM

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

laucian 02-20-2008 08:06 AM

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?


All times are GMT -5. The time now is 02:11 AM.