在 Debian 系统中,“清理流程”通常指系统垃圾清理、包管理清理、日志与缓存清理、自动化维护等方面。下面从手动优化和自动化优化两个维度,给你一套可落地的方案。
sudo apt clean
sudo apt autoclean
sudo apt autoremove --purge
建议加 --purge,连配置文件一起删。
sudo apt purge $(dpkg -l | grep 'linux-image' | grep -v $(uname -r) | awk '{print $2}')
⚠️ 保留当前运行内核。
sudo journalctl --vacuum-time=7d
sudo journalctl --vacuum-size=200M
永久限制(编辑 /etc/systemd/journald.conf):
SystemMaxUse=200M
MaxRetentionSec=1week
sudo rm -rf /tmp/*
或用 systemd 自动清理:
sudo systemctl enable --now systemd-tmpfiles-clean.timer
du -h / | sort -h | tail -20
rm -rf ~/.cache/*
sudo snap refresh
snap list --all
sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
/usr/local/bin/debian-clean.sh
#!/bin/bash
apt update
apt autoremove --purge -y
apt clean
journalctl --vacuum-time=7d
rm -rf /tmp/*
加执行权限:
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
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
启用:
systemctl enable --now debian-clean.timer
ncdu如果你愿意,可以告诉我:
我可以帮你定制一套专属清理策略。