Skip to content

Instantly share code, notes, and snippets.

@cmaureir
Created May 15, 2012 18:06
Show Gist options
  • Save cmaureir/2703802 to your computer and use it in GitHub Desktop.
Save cmaureir/2703802 to your computer and use it in GitHub Desktop.
Improved «du»
#!/bin/bash
du -sk ./* | sort -n | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment