• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

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!
0
GCaron
Asked:
GCaron
1 Solution
 
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
 
sardiskanCommented:
Oh, and it also counts the "hidden" folders and the . and .. things
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
omarfaridCommented:
try

cd /home
for dir in *
do
   cd $dir
        echo "number of users under $dir is `ls | wc`"
   cd ..
done
0
 
woolmilkporcCommented:
for dir in $(find /home -type d -maxdepth 1 -name "custom*") ; do echo $dir  "-->" $(ls $dir |wc -l); done
0
 
GCaronAuthor Commented:
Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now