1

I have a directory with a very large number of subdirectories (~800) that were generated programmatically. I want to get a count of the number of files in each of these subdirectories to check for anomalies (if the code broke on a run then some of the files will be missing). What's a quick way to do this? The sort of output I'm looking for is:

Name_of_Folder_1 [# of files in Folder 1]   
Name_of_Folder_2 [# of files in Folder 2]
...

2 Answers2

2

This will get you the count of files in each subdirectory of the current directory, dealing with any strange file names (with gnu find).

find . -maxdepth 2 -mindepth 2 -type f -printf "%h\0" | uniq -zc | tr '\0' '\n'
Matt
  • 8,991
1

Assuming that you have no spaces in your directory names:

for dir in $(find . -type d); do
    echo "${dir}: $(find ${dir} -maxdepth 1 -type f | wc -l)"
done
Andy Dalton
  • 13,993