Welcome to WebmasterWorld Guest from 188.8.131.52 , register , free tools , login , search , subscribe , help , library , announcements , recent posts , open posts Subscribe to WebmasterWorld
count files in a directory and each subdirectory jjc_mn msg:3087665 5:53 pm on Sep 18, 2006 (gmt 0) Has anybody written a short shell script that could be launched in any directory and it would list all the subdirectories and how many files in each specific subdirectory?
lammert msg:3087671 5:58 pm on Sep 18, 2006 (gmt 0)
Seems to be a popular topic:
...] webmasterworld.com jjc_mn msg:3087700 6:15 pm on Sep 18, 2006 (gmt 0)
That was a total count. I was looking for directory by directory file count so you could see how many files were in any subdirectory.
This will have to be a shell script in a for loop, not a quick one liner becuase the loop will first have to identify the subdirectory, then do the count, and then print subdirectory name and file count to the screen.
jjc_mn msg:3087795 7:46 pm on Sep 18, 2006 (gmt 0)
Couldn't wait. wrote it myself. Here it is in case anybody else finds themself with a Unix box running out of space.
#Counts files in subdirectories
date_stamp=`date +"%m%d%Y.%H%M%S"` temp_file="temp.$date_stamp.txt" find . -type d > $temp_file
exec 3< $temp_file
until [ $done ] do read <&3 myline if [ $?!= 0 ]; then done=1 continue fi dircount=`find $myline"/." \( -name . -o -prune \) -type f ¦ wc -l` echo "$dircount"$myline done rm $temp_file #EOF