温馨提示×

哪里找centos cleanup脚本

小樊
41
2026-09-09 02:34:38
栏目: 智能运维

CentOS cleanup(清理)脚本,可以从下面几个常用渠道和示例入手:


一、系统自带 / 官方文档

  1. CentOS 官方 Wiki

    • https://wiki.centos.org/
    • 搜索 cleanupdisk cleanup
  2. Red Hat 文档(CentOS 同源)

    • https://access.redhat.com/documentation/
    • 相关:包管理、日志轮转、临时文件清理

二、GitHub / Gist(最常用)

1. GitHub 搜索

直接在 GitHub 搜:

centos cleanup script
centos clean up shell
centos server cleanup

推荐关键词:

  • centos-cleanup.sh
  • linux-cleanup
  • server-hardening-cleanup

2. 常用示例仓库

  • https://github.com/topics/centos
  • https://github.com/search?q=centos+cleanup
  • https://gist.github.com(搜 centos cleanup

三、常见 CentOS 清理脚本内容(可直接用)

1. 基础清理脚本示例

#!/bin/bash
# centos-cleanup.sh

echo "== 清理 yum 缓存 =="
yum clean all

echo "== 删除旧内核 =="
package-cleanup --oldkernels --count=1 -y

echo "== 清理临时文件 =="
rm -rf /tmp/*
rm -rf /var/tmp/*

echo "== 清理日志 =="
journalctl --vacuum-time=7d
find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;

echo "== 清理 Docker(如已安装)=="
docker system prune -af

echo "清理完成"

四、系统工具(不用脚本也能做)

  • yum autoremove
  • package-cleanup
  • journalctl --vacuum-size=500M
  • logrotate

五、安全 / 生产环境建议

  • 不建议盲目 rm -rf
  • 生产服务器先测试
  • 可配合 cron 定期执行

如果你愿意,我可以:

  • 给你一份 CentOS 7 / 8 专用清理脚本
  • 或按你的用途(服务器 / 桌面 / Docker 主机)定制脚本

0