CentOS Spool 日志与临时文件清理策略
一 目录范围与风险识别
二 安全清理策略与示例
| 场景 | 推荐做法 | 命令示例 |
|---|---|---|
| 通用临时/旧文件 | 删除指定天数未访问的文件,避免误删子目录 | find /var/spool -mindepth 2 -type f -atime +7 -delete |
| 大文件快速止血 | 定位并清理超大临时文件 | find /var/spool -type f -size +100M -exec du -h {} + 2>/dev/null |
| 打印队列(CUPS) | 先排空队列,再清理残留 | cupsctl --purge-jobs;systemctl restart cups;find /var/spool/cups -mindepth 1 -type f -delete |
| 邮件队列(Postfix) | 优先用 postfix 命令排空,再清理残留 | postfix flush;find /var/spool/postfix -mindepth 1 -type f -mtime +2 -delete |
| 本地邮件收件箱 | 谨慎处理,避免误删未读邮件 | 按用户清理:find /var/spool/mail -type f -mtime +30 -delete(先确认无业务影响) |
| cron 临时文件 | 仅清理明显过期的临时/状态文件 | find /var/spool/cron -type f -mtime +7 -delete |
三 自动化与监控
四 常见误区与优化建议