在 Linux 系统中,“cleanup(清理)”通常包括磁盘空间清理、日志管理、包管理清理、临时文件清理、进程/服务清理等。下面按“高效且安全”的原则,给你一套实用方案。
先看清问题在哪,不要盲目删。
df -h # 看磁盘整体使用
du -h --max-depth=1 / # 看根目录下各目录大小
ncdu / # 交互式分析(推荐,需安装)
常见“重灾区”:
/var/log/tmp~/.cachesudo apt autoremove
sudo apt clean
sudo apt autoclean
sudo dnf autoremove
sudo dnf clean all
sudo pacman -Rns $(pacman -Qtdq)
sudo pacman -Scc
journalctl --disk-usage
sudo journalctl --vacuum-time=7d
sudo journalctl --vacuum-size=500M
sudo find /var/log -type f -name "*.log" -mtime +7 -delete
(建议配合 logrotate 使用)
sudo rm -rf /tmp/*
rm -rf ~/.cache/*
用户级缓存(如 pip / npm):
pip cache purge
npm cache clean --force
Ubuntu 示例:
dpkg -l | grep linux-image
sudo apt autoremove --purge
⚠️ 至少保留一个正在使用的内核。
docker system prune -a
docker volume prune
只清无用内容,不影响运行容器。
/etc/logrotate.conf
0 3 * * 0 apt autoremove -y && journalctl --vacuum-time=7d
bleachbit(图形化)ncdufslint(重复文件)✅ 先 du / ncdu 再删
✅ 不删不认识的 /usr, /lib
✅ 用 autoremove 而非手动删包
✅ 重要数据先备份
如果你愿意,可以告诉我:
我可以直接给你一条定制 cleanup 命令清单。