Count number of sub directories in directories

I am looking for an easy way to get a count of sub directories within an output of directories. Basically I am trying to get a count of users per customer. They each have a directory:

/home/customer/

then under that they have users

/home/customer/users/

I am trying to get an easy command that will output the customer name (/home/customer/) with the number of user directories under that.

I am just using "ls -l /home/*" which prints out the user directories which I then have to manually count. I am sure there is a much easier way.

Thanks in advance!
GCaronAsked:
Who is Participating?
 
woolmilkporcCommented:
for dir in $(find /home -type d -maxdepth 1 -name "custom*") ; do echo $dir  "-->" $(ls $dir |wc -l); done
0
 
sardiskanCommented:
Try:

find ./ -type d|wc

where ./ is the subdirectory you want to count. The first or second number should be the folder count.
0
 
GCaronAuthor Commented:
That looks to work if I'm in the customers directory but I have 150+ customers and don't want to have to go to each one and issue the command.

I have

/home/customer1/user1
/home/customer1/user2
/home/customer2/user1
/home/customer2/user2
/home/customer2/user3
etc...

I would like to issue one command to list out the number of users in each customer directory.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
sardiskanCommented:
Oh, and it also counts the "hidden" folders and the . and .. things
0
 
omarfaridCommented:
try

cd /home
for dir in *
do
   cd $dir
        echo "number of users under $dir is `ls | wc`"
   cd ..
done
0
 
GCaronAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.