Welcome to WebmasterWorld Guest from 126.96.36.199 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
count files in a directory and each subdirectory jjc_mn
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?
Seems to be a popular topic:
...] webmasterworld.com jjc_mn
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.
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