Linux: 找出前 10 个最近更新的文件/文件夹

Linux: Find out top 10 recently updated files / folders

我想找出 linux 中消耗最多的文件或文件夹,其中消耗最多的 space(以人类可读的形式 - 以 MB 或 GB 为单位)文件或文件夹应该是最近修改过 - 例如在上个月内。

我怀疑这是 du -exec、sort、ls 命令的组合,但可以指定是哪个?

使用 CLI

du -hsc * | sort -h

每个选项对 du 的意义:

h: show sizes in human readable format (1K, 1M, 1G, ...)
s: summarize: display only a total for each argument
c: also display a grand total

如果需要 GUI,可以使用磁盘使用分析器

如果你真的想要前10名,你可以使用:

du -h | sort -h | tail -10

在 CentOS 中,没有 sort -h,你可以试试这个:

du -h | sort -nr | tail -10

上个月修改的最耗费文件:

find "$PWD" -type f -mtime -30 -exec du -sh '{}' + | sort -rh | head

上个月修改的最常用文件夹:

find "$PWD" -type d -mtime -30 -exec du -sh '{}' + | sort -rh | head

如果您的 sort 版本不支持 -h 选项,您可以尝试:

find "$PWD" -type f -mtime -30 -exec du -s '{}' + | sort -nr | head | cut -f2- | xargs -d'\n' du -sh

您可以使用 https://www.diskreport.net/ 等工具来跟踪您的磁盘使用历史记录图