Skip to content

Instantly share code, notes, and snippets.

@aculich
Last active November 28, 2017 18:06
Show Gist options
  • Select an option

  • Save aculich/e301b2feb8f09b3835b358a59d5c8fc2 to your computer and use it in GitHub Desktop.

Select an option

Save aculich/e301b2feb8f09b3835b358a59d5c8fc2 to your computer and use it in GitHub Desktop.
A useful RDM (Research Data Management) utility for examining the distribution of file sizes
#!/bin/bash
# Based on: https://superuser.com/a/1100340/58245
DIR=${1:-.}
# One-liner version of what's expanded below:
#
# find $DIR -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) }'
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) }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment