Skip to content

Instantly share code, notes, and snippets.

@albatrossflavour
Created August 11, 2014 04:50
Show Gist options
  • Save albatrossflavour/59b52930606611d38a50 to your computer and use it in GitHub Desktop.
Save albatrossflavour/59b52930606611d38a50 to your computer and use it in GitHub Desktop.
#!/bin/sh
human_readable()
{
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
human_readable $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment