Count files in all subdirectories, by directory

By jbayer - Last updated: Friday, June 22, 2012 - Save & Share - Leave a Comment

This is a quickie. I had a need to see how many files were in each directory (not including files in directories underneath)

This little script will do just that, and save the output in a file called “b.csv” (I was lazy).  The file will be formatted as a comma separated csv, which you can load into any spreadsheet:

 [ $# -ne 0 ] && dir=$1
 echo $dir
#echo "ls -1 $1 | wc -l" >
 echo "find . -maxdepth 1 -type f -print | wc -l" >
 chmod +x
 find $dir -type d -print -exec ./ {} \; | awk '{printf("%s%s", $0, (NR%2 ? "," : "\n"))}' >b.csv


Posted in Bash, Programming • • Top Of Page

Write a comment