在 Ubuntu 上安排“清理计划”,通常做法是**用系统自带工具 + 定时任务(cron / systemd timer)**组合。下面按「做什么 → 怎么定时 → 示例方案」给你一套实用方案。
常见可清理项:
/var/cache/apt/archives/var/log~/.cache/tmpsudo apt autoremove --purge -y
sudo apt clean
sudo journalctl --vacuum-time=7d
dpkg -l | grep linux-image
sudo apt remove linux-image-旧版本
rm -rf ~/.cache/*
docker system prune -af
sudo crontab -e
0 3 * * 0 apt autoremove --purge -y && apt clean && journalctl --vacuum-time=7d
0 2 * * * find /tmp -type f -mtime +7 -delete
sudo nano /usr/local/bin/ubuntu-clean.sh
内容:
#!/bin/bash
apt autoremove --purge -y
apt clean
journalctl --vacuum-time=7d
find /tmp -type f -mtime +7 -delete
sudo chmod +x /usr/local/bin/ubuntu-clean.sh
sudo nano /etc/systemd/system/clean.service
[Unit]
Description=Ubuntu Cleanup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/ubuntu-clean.sh
sudo nano /etc/systemd/system/clean.timer
[Unit]
Description=Weekly Ubuntu Cleanup
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
sudo systemctl enable --now clean.timer
systemctl list-timers
crontab -l
df -h
cron 每周清一次systemd timerdocker system prune如果你愿意,我可以按你的 Ubuntu 版本 / 是否服务器 / 是否用 Docker帮你定制一份现成配置。