GCaron
asked on
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!
/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!
ASKER
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.
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.
Oh, and it also counts the "hidden" folders and the . and .. things
try
cd /home
for dir in *
do
cd $dir
echo "number of users under $dir is `ls | wc`"
cd ..
done
cd /home
for dir in *
do
cd $dir
echo "number of users under $dir is `ls | wc`"
cd ..
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
find ./ -type d|wc
where ./ is the subdirectory you want to count. The first or second number should be the folder count.