日常工作中,会遇到一堆目录,如何查看各目录大小呢,大家都知道du命令
先列出前10条
[email protected] /scripts]#du -sh * | head 120K 2017031510 248K 2017031514 23M 2017031515 664K 2017031516 656K 2017031517 2.0M 2017031518 68K 2017031519 884K 2017031520 580K 2017031521 60K 2017031609
再排序
[email protected] /scripts]#du -sh * | sort -nr | head 1020K 2017062120 1008K 2017033016 1000K 2017032221 988K 2017052420 988K 2017033118 988K 2017031912 98K 2017032810 80K 2017051114 76M 2017050918 68K 2017052010
是不是乱了?这是du命令中-h导致的,先计算了大小,但是在排序的时候,只针对数字,不会识别后面的K 和 M ,优化下
[email protected] /scripts]#du -s * | sort -nr | head | awk ‘{printf"%sM\n",$1/1024 }‘ 125.906M 66.4023M 65.8516M 63.5117M 53.5859M 53.125M 51.4805M 47.8945M 46.8867M 44.25M
OK了
时间: 2024-10-30 13:40:43