I created a file in my home folder called filecnt, which contains the following lines of code:
for d in *; do
if [[ -d $d ]]; then
echo `find $d -type f | wc -l` $d;
fi
done | sort -n -k1
Then I changed the file permissions to allow execute:
chmod 755 ~/filecnt
Now, from any directory, I can run ~/filecnt to see a list of sub-directories in the current directory with their recursive file counts. The list is sorted by file count (ascending). For example:
0 access-logs
20 logs
187 etc
232 cache
694 tmp
30007 mail
48325 public_html
You can accomplish the same by simply running the following command from the CLI:
for d in *; do if [[ -d $d ]]; then echo `find $d -type f | wc -l` $d; fi done | sort -n -k1
Add -r to the final sort command to sort descending.
To produce a slightly more pleasing output, you can also use the following code in ~/filecnt instead of the code at the top of this answer:
echo "File Count Dir Size Directory"
echo "---------- ---------- -------------------------"
for d in *; do
if [[ -d $d ]]; then
echo `find $d -type f | wc -l` | awk '{printf "%10s ", $0;}'
echo `du -h --max-depth=0 $d` | cut -d\ -f 1 $1 | awk '{printf "%10s ", $0;}'
echo $d
fi
done | sort -n -k1
echo
The output looks like this:
File Count Dir Size Directory
---------- ---------- -------------------------
0 0 access-logs
20 8.3M logs
187 4.8M etc
232 228K cache
694 23M tmp
30715 6.4G mail
48272 2.3G public_html