一句话:

du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e';  

显示如下:

23.8G    .  
15.1G    ./Photo  
1.7G    ./img  
473.8M    ./Ruby  
253.2M    ./ghost  
118.2M    ./elastic  
72.9M    ./stock  
63.8M    ./proxy  
...

建议放到/etc/profile里面做成函数

sbs() { du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e';}  
comments powered by Disqus