du -hs * | sort -hr | head
70M chapter04
30M chapter02
580K chapter03
48K chapter06
48K chapter01
36K chapter05
16K README.md
8.0K chapter07
0 requirements.txt
# head是显示前10个
du --help
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-s, --summarize display only a total for each argument
sort --help
-h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)
-r, --reverse reverse the result of comparisons
# 从大到小排序,可以用--max-depth指定文件夹深度
du --max-depth 1 -h | sort -hr
# 指定目录:
du /tmp -hs * | sort -hr
Linux du命令查看文件夹大小并排序
最新推荐文章于 2022-01-15 10:35:32 发布
这篇博客介绍了如何使用Linux命令`du`和`sort`来查看和排序目录中文件的大小。通过`du -hs *`和`du --max-depth=1 -h | sort -hr`等命令,可以获取并按人类可读格式排序文件大小,便于管理和清理磁盘空间。此外,还展示了如何限制文件夹深度以及如何针对特定目录进行操作。
摘要由CSDN通过智能技术生成