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".
Written by Steve McHail
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Related Tags
#shell
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#