“Linux cleanup 问题”范围比较广,通常指系统清理(磁盘、日志、缓存、临时文件等)后出现的异常,或清理脚本/定时任务(cleanup)本身执行异常。下面按「常见场景 → 排查思路 → 实用命令」给你一个系统化的排查框架。
先确认问题现象:
df 仍满)df -h # 显示 100%
du -sh /* # 总和使用远小于 df
文件被删除,但仍有进程占用
# 查看被删除但仍被占用的文件
lsof | grep deleted
# 或
find /proc/*/fd -ls 2>/dev/null | grep deleted
> /path/to/file
/var/log/*/tmp/*/var/lib/*journalctl -xe
systemctl status xxx
ls -l /var/log
touch /var/log/xxx.log
chown user:group /var/log/xxx.log
crontab -l
systemctl status cron
grep cron /var/log/syslog
systemctl list-timers
systemctl status cleanup.service
journalctl -u cleanup.service
ls -l /path/cleanup.sh
chmod +x /path/cleanup.sh
bash -x cleanup.sh
rm -rf 路径为空 → 删根rm -rf "${DIR:?}"/*
sync
echo 3 > /proc/sys/vm/drop_caches
free -h
dmesg | grep oom
避免手写风险:
logrotatesystemd-tmpfilesapt autoremovebleachbit(桌面)✅ df vs du 不一致 → lsof deleted
✅ 服务异常 → journalctl
✅ 定时任务 → cron / timer 日志
✅ 脚本问题 → bash -x
✅ 权限问题 → ls -l / chmod
如果你能补充:
我可以给你更精确的排查步骤。