Last Updated: February 25, 2016
·
579
· mchail

Count files in a directory by file size

I found myself needing a frequency plot of file sizes in a directory. Some googling and refactoring left me with this to grab the data:

ls -l | awk '{ A[$5]++ } END { for(X in A) printf("%s\t%s\n", X, A[X]) }'

Output will look something like this:

               1
2958           1
170068         1
3785        4995
0              5

Ignore the first line with a blank size; that just ls's "total".