在 Debian 系统上“清理流程”通常指系统瘦身、释放磁盘空间、减少冗余文件和提升可维护性。下面从常规清理 → 自动化 → 进阶优化三个层次给你一套可落地的方案。
apt-get clean
apt-get autoclean
clean:删除所有已下载的 .debautoclean:只删过期包apt-get autoremove --purge
⚠️ 务必加 --purge,否则配置文件会残留
dpkg -l | grep linux-image
apt-get remove --purge linux-image-旧版本
或自动化:
apt-get autoremove --purge
#!/bin/bash
set -e
apt-get update
apt-get autoremove --purge -y
apt-get autoclean -y
apt-get clean
journalctl --vacuum-time=7d
rm -rf /var/tmp/*
保存为 /usr/local/bin/debian-clean.sh
chmod +x /usr/local/bin/debian-clean.sh
/etc/systemd/system/debian-clean.service
[Unit]
Description=Debian Cleanup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/debian-clean.sh
/etc/systemd/system/debian-clean.timer
[Unit]
Description=Weekly Debian Cleanup
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
启用:
systemctl enable --now debian-clean.timer
/etc/systemd/journald.conf
SystemMaxUse=200M
MaxRetentionSec=2week
然后:
systemctl restart systemd-journald
rm -rf /tmp/*
rm -rf /var/tmp/*
systemctl list-unit-files | grep enabled
关闭例子:
systemctl disable bluetooth
deborphan 找孤儿包apt install deborphan
deborphan
apt-get remove --purge $(deborphan)
cruft-ng(高级)apt install cruft-ng
cruft
debootstrap 或 minimaltask-desktop 等元包apt-get install --no-install-recommendsdu -h /var | sort -rh | head
ncdu
如果你愿意,可以告诉我:
我可以帮你定制一套最合适的 Debian 清理方案。