Skip to content

Instantly share code, notes, and snippets.

@techie2000
Created March 24, 2022 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techie2000/ed48b3315c3fd04e459321f6b3ab8f0d to your computer and use it in GitHub Desktop.
Save techie2000/ed48b3315c3fd04e459321f6b3ab8f0d to your computer and use it in GitHub Desktop.
histogram of file sizes, and how many files are in that size range.
find . -type f -print0 | xargs -0 ls -l | awk '{ n=int(log($5)/log(2)); if (n<10) { n=10; } size[n]++ } END { for (i in size) printf("%d %d\n", 2^i, size[i]) }' | sort -n | awk 'function human(x) { x[1]/=1024; if (x[1]>=1024) { x[2]++; human(x) } } { a[1]=$1; a[2]=0; human(a); printf("%3d%s: %6d\n", a[1],substr("kMGTEPYZ",a[2]+1,1),$2) }'
--e.g.
-- 1k: 270448
-- 2k: 72548
-- 4k: 74510
-- 8k: 62799
-- 16k: 36386
-- 32k: 74070
-- 64k: 21528
--128k: 30624
--256k: 25892
--512k: 83264
--1M: 140595
--2M: 23716
--4M: 14846
--8M: 4843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment