The best way to use du to sort through your storage
(and you never tought about)
I often find myself using this one-liner to quickly sort through folders and determine which ones consume the most storage space within a specific directory.
du -bx --max-depth=1 2>/dev/null | sort -rn | awk -F/ -v c=$COLUMNS 'BEGIN { split("B,KB,MB,GB,TB,PB,EB,ZB,YB",SZ,",") } NR==1{t=$1} NR>1{r=int($1/t*c+.5); b="\033[1;31m"; for (i=0; i<r; i++) b=b"#"; p=1;for(i=0;$1/p>1024;i++) p*=1024; printf "%6.1f %s %5.2f%% %s\033[0m %s\n", $1/p, SZ[i+1], $1/t*100, b, $2}' | tac
Yes, I know that it looks absolutely ugly, but after a few seconds the output will look something like:
650.7 KB 0.01% config-files
5.8 MB 0.08% tmp
407.3 MB 5.98% ########## radio
1.2 GB 18.77% ######################### personal
5.0 GB 75.14% ################################################ work
I’m still trying to figure out the origin of this one.