在 Linux 里,“cleanup(清理)”通常指系统资源、进程、临时文件、磁盘、容器/服务等的清理操作。验证 cleanup 是否“真的生效”,一般从结果检查 + 日志 + 监控三方面入手。下面按常见场景给出验证方法。
df -h
对比清理前后:
df -h /tmp
ls -lh /tmp
du -sh /var/log/*
systemd-tmpfiles --clean
检查:
systemctl status systemd-tmpfiles-clean
ps aux | grep <process>
pgrep -a <process>
ss -lntp | grep <port>
netstat -lntp
systemctl stop myservice
systemctl is-active myservice
应为:
inactive
free -h
sync
echo 3 > /proc/sys/vm/drop_caches
free -h
观察 buff/cache 是否下降。
journalctl --disk-usage
清理:
journalctl --vacuum-size=100M
再次:
journalctl --disk-usage
logrotate -d /etc/logrotate.conf
(-d 是 dry-run,不实际删除)
docker ps -a
docker container prune
docker ps -a
docker images
docker volume ls
docker system df
如果是你写的 cleanup 脚本:
示例:
before=$(df -h / | awk 'NR==2{print $5}')
./cleanup.sh
after=$(df -h / | awk 'NR==2{print $5}')
echo "Before: $before After: $after"
✅ 看资源是否减少
✅ 看进程/端口是否消失
✅ 看日志是否记录成功
✅ 用前后对比而不是“以为清了”
如果你指的是某一类 cleanup(比如:kernel cleanup、Kubernetes cleanup、CI/CD cleanup、自写脚本),可以直接说场景,我可以给你更精确的验证命令。