Skip to content

Instantly share code, notes, and snippets.

@stojg stojg/diskspace.sh
Last active Sep 12, 2018

Embed
What would you like to do?
Find sizes of folders in a with a bash oneliner
#!/bin/sh
# Installation: curl -o diskspace.sh "https://gist.githubusercontent.com/stojg/867224/raw/diskspace.sh" && chmod +x 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
You can’t perform that action at this time.