You’ve probably wanted ‘du’ to print in a tree formation at some point to make it easier to comprehend… right? Right? Well, I know I have!
Here’s my pretty little zsh alias: pdu () {du $1 | sort +1 -2 | expand | awk -F/ ’{for (i = 0; i < NF; ++i) printf ” ”; print; }’ }
What’s it do? Simple!
5:57 [procyon] /tmp%pdu 88 . 56 ./501 40 ./501/Cleanup At Startup 16 ./501/Temporary Items 5:57 [procyon] /tmp%Now, if we want to get reallly convoluted, we can… but for the sake of brevity.. MacOS X’s native du doesn’t have the logic to print human-legable filesizes. This sucks. Again, awk to the rescue!
5:58 [procyon] /Users/shawn/Documents/Music/Collections%du -k | awk ’{if($1>1024){r=$1%1024;if(r!=0) {sz=($1-r)/1024}else{sz=$1/1024}print sz”M ”$2-;} else{print $1”k ”$2}}’ 37M ./Fletch 37M . 5:58 [procyon] /Users/shawn/Documents/Music/Collections%