Skip to content

Instantly share code, notes, and snippets.

@gullevek
Created July 6, 2018 01:11
Show Gist options
  • Save gullevek/b4bf9535e1624e4a29393a7765aebc4a to your computer and use it in GitHub Desktop.
Save gullevek/b4bf9535e1624e4a29393a7765aebc4a to your computer and use it in GitHub Desktop.
Find files and group the file size sum per year
find ./ -type f -print0 | xargs -0 stat -f '%Sm %z' -t "%Y" | awk 'function human(x) {s=" B KB MB GB TB EB PB YB ZB"; while (x>=1024 && length(s)>1){x/=1024; s=substr(s,4)} s=substr(s,1,4); xf=(s==" B ")?"%d ":"%.2f"; return sprintf( xf"%s", x, s);}{sum[$1]+= $2;}END{for (date in sum){printf ("%s %s\n", date, human(sum[date]));}}' | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment