温馨提示×

CentOS系统中大文件如何查找并清理

小樊
52
2026-01-06 03:57:35
栏目: 智能运维

在CentOS系统中,你可以使用find命令来查找大文件,并使用rm命令来删除它们。以下是一些示例:

  1. 查找当前目录及其子目录中大于100MB的文件:
find /path/to/directory -type f -size +100M

这里,/path/to/directory是你想要搜索的目录,-type f表示只查找文件,-size +100M表示查找大于100MB的文件。

  1. 查找当前目录及其子目录中大于100MB的文件,并将结果保存到文件中:
find /path/to/directory -type f -size +100M > large_files.txt
  1. 删除当前目录及其子目录中大于100MB的文件:
find /path/to/directory -type f -size +100M -exec rm {} \;
  1. 如果你想要删除特定类型的文件(例如,.log文件),可以使用-name选项:
find /path/to/directory -type f -size +100M -name "*.log" -exec rm {} \;
  1. 在删除文件之前,你可以先使用ls命令查看找到的文件:
find /path/to/directory -type f -size +100M -exec ls -lh {} \;

请注意,在删除文件之前确保你真的想要删除这些文件,因为删除操作是不可逆的。建议先备份重要数据。

0