温馨提示×

centos cleanup有哪些好工具

小樊
46
2026-09-21 08:51:44
栏目: 智能运维

在 CentOS(以及一般 RHEL 系)系统上,常用的系统清理/运维工具可以分为几类:系统自带命令、官方仓库工具、第三方清理工具。下面按“实用程度”给你梳理一下。


一、系统自带 / 官方推荐(最安全)

1. yum / dnf 清理(最常用)

# 清理 yum 缓存
yum clean all

# 删除无用依赖
yum autoremove

# CentOS 8+(dnf)
dnf autoremove
dnf clean all

2. package-cleanup(来自 yum-utils)

yum install yum-utils

# 删除重复包
package-cleanup --dupes

# 删除旧内核(保留当前和最新)
package-cleanup --oldkernels --count=2

3. journalctl(日志清理)

# 查看日志占用
journalctl --disk-usage

# 清理旧日志
journalctl --vacuum-time=7d
journalctl --vacuum-size=500M

4. logrotate

系统自带,用于管理 /var/log 日志:

logrotate -d /etc/logrotate.conf  # 测试
logrotate /etc/logrotate.conf     # 执行

二、磁盘 / 文件清理工具

5. ncdu(强烈推荐)

交互式磁盘占用分析工具

yum install ncdu
ncdu /

6. du / df(基础但必备)

df -h
du -sh /*

7. bleachbit(图形/命令行)

类似 CCleaner

yum install bleachbit
bleachbit --clean system.cache system.tmp

⚠️ 谨慎使用,避免清错系统文件


三、进阶 / 自动化清理

8. tmpwatch / tmpreaper

清理 /tmp 旧文件

tmpwatch 7d /tmp

9. systemd-tmpfiles

CentOS 7+

systemd-tmpfiles --clean

10. fstrim(SSD)

fstrim -v /

四、容器 / 服务相关(如适用)

11. Docker 清理

docker system prune -a

12. Kubernetes 节点清理

kubectl drain node

五、推荐组合方案(日常维护)

yum clean all
yum autoremove -y
journalctl --vacuum-time=7d
ncdu /

如果你是 CentOS 7 / 8 / Stream,或者用途是 服务器 / 桌面 / 容器主机,可以告诉我,我可以给你一套更针对性的清理脚本。

0 踩