This question already has an answer here:

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]

marked as duplicate by don_crissti, jimmij, cuonglm, Ramesh, Anthon Aug 13 '15 at 5:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

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)"

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'

Not the answer you're looking for? Browse other questions tagged or ask your own question.