Debian 本身没有像 Windows 那样“一键清理垃圾”的内置功能,但可以通过系统和工具自动清理不必要的文件。下面分层次说明。
Debian 用 apt 安装软件后会保留 .deb 包在:
/var/cache/apt/archives/
自动清理方式:
sudo apt autoclean
sudo apt autoremove
可设为定时任务(cron):
# 每天清理
0 3 * * * apt-get autoclean && apt-get autoremove -y
# 只保留最近 7 天日志
journalctl --vacuum-time=7d
或配置:
sudo nano /etc/systemd/journald.conf
SystemMaxUse=500M
MaxRetentionSec=1week
Debian 默认 自动轮转并清理日志
配置文件:
/etc/logrotate.conf
/etc/logrotate.d/
Debian 默认:
/tmp 重启后清空(部分版本)systemd-tmpfiles可手动清理:
sudo rm -rf /tmp/*
旧内核会占很多空间:
dpkg -l | grep linux-image
自动删除旧内核:
sudo apt autoremove --purge
unattended-upgrades(自动更新+清理)sudo apt install unattended-upgrades
它可自动:
bleachbit(图形化清理)sudo apt install bleachbit
⚠️ 谨慎使用,不要勾选“系统关键项”
ncdu(查找大文件)sudo apt install ncdu
ncdu /
⚠️ 原因:
✅ Debian 可以自动清理
❌ 但不是“无脑清理垃圾”
最佳实践:
apt autoremovejournalctl --vacuumlogrotateunattended-upgradesncdu 检查如果你愿意,我可以: