LinuxQuestions.org
Visit Jeremy's Blog.
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 03-13-2009, 12:53 AM   #1
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Rep: Reputation: 15
Number of home directories


I'm working on something for school and I think I'm right, but I'm not exactly sure. I am trying to get the total number of /home directories that are within crux. This is the command that I have entered and the answer I have came up with, am I doing it right or wrong?

$ ls /home -n | more
Total 51764
[ then lists off all the users id and so forth ] Like for example the first line after the total is like this:

d---rwx--t 12 300 724 4096 Sep 21 2006 userid

Would this be correct or am I missing something?

Last edited by shorte85; 03-13-2009 at 12:55 AM.
 
Old 03-13-2009, 01:16 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
You could extract the information from /etc/passwd as well.

Code:
# UID_MIN & UID_MAX from /etc/login.defs
UID_MIN=1000
UID_MAX=60000

awk -F: '($3 >= '$UID_MIN') && ($3 <= '$UID_MAX') {print $1, $3}' /etc/passwd
If you want just a count of the users, either add counting logic to the awk script, or pipe the output through 'wc -l'.
You could have a server where some users have home pages at different places. For example, /home, /mnt/remote1/, /mnt/remote2/.
I could easily imagine that you decide to add a hard drive for new users, and mount it as /home2. So you can't always rely on the location of a users home directory.

Also, you may have a group directory under /home as well for a group of users to share files.
For example, /home/webwork/, owned by root, with group ownership of webwork. Then users if the webwork group could access files there.

----

I should mention tip in case you want to modify my example or do something similar in the future.
Precede your command with `set' and look at $@, $1, $2, etc. This is an easy debugging tip to check if the command line arguments are what you think they are.
Compare:

Code:
jschiwal@qosmio:~> awk -F: '($3 >= '$UID_MIN') && ($3 <= '$UID_MAX') {print $1, $3}' /etc/passwd
jschiwal 1000
testuser 1001
tuser 1002
jschiwal@qosmio:~> set awk -F: '($3 >= '$UID_MIN') && ($3 <= '$UID_MAX') {print $1, $3}' /etc/passwd
jschiwal@qosmio:~> echo $0 $1 $2
/bin/bash awk -F:
jschiwal@qosmio:~> echo $0
/bin/bash
jschiwal@qosmio:~> echo $3
($3 >= 1000) && ($3 <= 60000) {print $1, $3}
jschiwal@qosmio:~> echo $@
awk -F: ($3 >= 1000) && ($3 <= 60000) {print $1, $3} /etc/passwd
Code:
jschiwal@qosmio:~> awk -F: '($3 >= '$UID_MIN') && ($3 <= ' $UID_MAX ') {print $1, $3}' /etc/passwd
awk: cmd. line:1: ($3 >= 1000) && ($3 <=
awk: cmd. line:1:                        ^ unexpected newline or end of string
jschiwal@qosmio:~> set awk -F: '($3 >= '$UID_MIN') && ($3 <= ' $UID_MAX ') {print $1, $3}' /etc/passwd
jschiwal@qosmio:~> echo $@
awk -F: ($3 >= 1000) && ($3 <= 60000 ) {print $1, $3} /etc/passwd
jschiwal@qosmio:~> echo $0
/bin/bash
jschiwal@qosmio:~> echo $1
awk
jschiwal@qosmio:~> echo $2
-F:
jschiwal@qosmio:~> echo $3
($3 >= 1000) && ($3 <=
jschiwal@qosmio:~> echo $4
60000
jschiwal@qosmio:~> echo $5
) {print $1, $3}

Last edited by jschiwal; 03-13-2009 at 01:28 AM.
 
Old 03-13-2009, 01:45 AM   #3
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
By all the stuff you just gave me to read, I am really confused. LOL I just really wanted to know if the command that I did was correct or not? If not, what did or where did I go wrong?

Sorry, I am a beginner in linux and haven't gotten that far in class yet.
 
Old 03-13-2009, 02:14 AM   #4
alpha01
Member
 
Registered: Jul 2008
Location: Orange County
Distribution: Ubuntu/Debian, CentOS, RHEL, FreeBSD, OS X
Posts: 75

Rep: Reputation: 19
Quote:
Originally Posted by shorte85 View Post
I'm working on something for school and I think I'm right, but I'm not exactly sure. I am trying to get the total number of /home directories that are within crux. This is the command that I have entered and the answer I have came up with, am I doing it right or wrong?

$ ls /home -n | more
Total 51764
[ then lists off all the users id and so forth ] Like for example the first line after the total is like this:

d---rwx--t 12 300 724 4096 Sep 21 2006 userid

Would this be correct or am I missing something?

I'm not sure if you really asked your question properly.
By number of home directories, are you asking for the number of directories that exists within /home?

try running
Code:
ls -l | wc -l
or pipe it to a file if you want to analyze it
Code:
ls -l | wc -l > output.txt
Also the
Code:
ls -R
option lets you view sub directories as well.
 
Old 03-13-2009, 05:10 AM   #5
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
I guess what I am trying to do is see how many home directories there are in crux.

So I'm trying to establish a simple command that will tell me how many home directories are in crux. Basically the total number, so that I don't have to sit there and count them manually. lol

I hope I'm wording this so it's understandable.

Last edited by shorte85; 03-13-2009 at 03:15 PM.
 
Old 03-14-2009, 08:20 PM   #6
shorte85
Member
 
Registered: Mar 2009
Posts: 47

Original Poster
Rep: Reputation: 15
I hope I said that correctly so that it's more understandable?
 
Old 03-15-2009, 12:52 PM   #7
stratotak
Member
 
Registered: Sep 2005
Distribution: Today Debian . Tomorrow ..??
Posts: 386

Rep: Reputation: 39
I dont have but 1 home directory..but try this..wc stands for word count
Code:
strat@debian:~$ ls /home | wc
      1       1       6
strat@debian:~$
or maybe this way
Code:
strat@debian:~$ cat /etc/passwd |grep "/home" |cut -d: -f1
strat
strat@debian:~$ cat /etc/passwd |grep "/home" |cut -d: -f1 |wc
      1       1       6
strat@debian:~$

Last edited by stratotak; 03-15-2009 at 01:09 PM.
 
  


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
Maximum number of directories under XFS ttsang123 Linux - Newbie 6 02-24-2010 01:26 PM
Apache Root/Home Directory and setting up FTP for home directories? Mankind75 Linux - Newbie 6 07-23-2006 03:37 PM
number of directories in root? jayandstuff Slackware 2 02-23-2006 12:13 PM
List total number of directories paraiso Linux - Newbie 5 04-18-2005 05:04 AM
Number of files and directories ALF Linux - Software 4 06-11-2003 11:34 AM


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