Created
April 6, 2021 16:27
-
-
Save arm2arm/50a5362654f5c2d2385add3da9012dfe to your computer and use it in GitHub Desktop.
getting histogram of the filesystem files sizes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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