Operating System - HP-UX
1834149 Members
2564 Online
110064 Solutions
New Discussion

Report total number of files in each subdirectory.

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

Report total number of files in each subdirectory.

We have a “/psoft” mount point having more than 100,000 files in several recursive subdirectories, mostly log files.

I would like to get a report of total number of files in each subdirectory.

For example:

/psoft/dir1 400
/psoft/dir1/subdir1/ 500
/psoft/dir2 600

Thanks,


Gulam.
Everyday Learning.
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: Report total number of files in each subdirectory.

Hi Gulam:

Here's a simple approach for what I think you want:

find /mountpoint -xdev -type d > /tmp/mydirs
while read DIR
do
find ${DIR} -xdev -type f -print|wc -l
done < /tmp/mydirs

Regards!

...JRF...
Christian Tremblay
Trusted Contributor

Re: Report total number of files in each subdirectory.

try:

for i in `find /psoft -type d`;do echo $i;ll $i|wc -l;done

Chris
Peter Nikitka
Honored Contributor

Re: Report total number of files in each subdirectory.

Hi,

if your example output is written correctly, you do NOT want to have the counting of files done recursivly, because then this numbers where impossible:

/psoft/dir1 400
/psoft/dir1/subdir1/ 500 (larger than the number of the parent directory)

So try:
find /psoft -type d -print | xargs -i /bin/sh 'printf {}: ;ls -p {} | grep -cv "/$"'

mfG Peter


The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"