Skip to content

Instantly share code, notes, and snippets.

@arm2arm
Created April 6, 2021 16:27
Show Gist options
  • Save arm2arm/50a5362654f5c2d2385add3da9012dfe to your computer and use it in GitHub Desktop.
Save arm2arm/50a5362654f5c2d2385add3da9012dfe to your computer and use it in GitHub Desktop.
getting histogram of the filesystem files sizes
# Usage:
# sh ./fs_hist.sh /data/archive
mypath=$1
find $mypath -type f | wc -l
find $mypath -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) }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment