Skip to content

Instantly share code, notes, and snippets.

@stojg
Last active June 8, 2022 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stojg/867224 to your computer and use it in GitHub Desktop.
Save stojg/867224 to your computer and use it in GitHub Desktop.
Find sizes of folders in a with a bash oneliner
#!/bin/sh
# Installation: curl -o /usr/bin/diskspace.sh "https://gist.githubusercontent.com/stojg/867224/raw" && chmod +x /usr/bin/diskspace.sh
du -xsk ./* | 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",int(x*10)/10,pref[y],$0); } { for (i=2; i<=NF; i++) printf "%s ", $i; printf "\n"; } 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