温馨提示×

如何排查linux cleanup

小樊
46
2026-10-08 08:14:31
栏目: 智能运维

“Linux cleanup” 这个词可能有几种含义,我先按最常见的三种场景给你排查思路,你可以对照自己的情况:


一、系统自动 cleanup(如 systemd-tmpfiles / tmpwatch / apt autoremove)

1. 查看是否由 systemd 定时清理

systemctl status systemd-tmpfiles-clean
systemctl list-timers | grep tmpfiles

配置文件位置:

/etc/tmpfiles.d/
/usr/lib/tmpfiles.d/

重点看 tmp.conf 里对 /tmp、/var/tmp 的清理规则。

2. 排查 apt / yum 自动清理

# Debian/Ubuntu
cat /etc/apt/apt.conf.d/* | grep -i clean
apt-config dump | grep Clean

# RHEL/CentOS
cat /etc/yum.conf | grep clean

3. 检查 cron 定时任务

crontab -l
ls -l /etc/cron.daily/ /etc/cron.weekly/
cat /etc/cron.daily/tmpwatch 2>/dev/null

二、某个程序 / 脚本执行了 cleanup(你发现文件被删)

1. 查审计日志(audit)

ausearch -m DELETE -ts recent

或

journalctl | grep -i cleanup

2. 查进程历史

history | grep cleanup
ps aux | grep cleanup

3. 查最近被删文件(ext4 / xfs)

lsof | grep deleted

4. 查自定义脚本

grep -R "rm -rf" /etc /usr/local /opt 2>/dev/null

三、你是指“如何安全做 Linux 清理”(主动排查垃圾)

1. 磁盘占用排查

df -h
du -sh /* 2>/dev/null

2. 常见可清理项

# 包缓存
apt clean
yum clean all

# 旧内核
dpkg -l | grep linux-image
apt autoremove --purge

# 日志
journalctl --vacuum-time=7d

3. 容器 / 镜像清理

docker system df
docker system prune

你可以补充的信息(方便我精准回答)

  • 是文件被莫名其妙删了,还是想做清理?
  • 用的发行版(Ubuntu / CentOS / Alpine?)
  • 有没有报错日志或现象截图

我可以直接帮你定位是哪一层在做 cleanup。

0 踩