以下是CentOS下优化磁盘空间使用的方法:
sudo rm -rf /tmp/*。sudo yum clean all(CentOS 7)或 sudo dnf clean all(CentOS 8)。sudo yum autoremove(CentOS 7)或 sudo dnf autoremove(CentOS 8)。sudo package-cleanup --oldkernels --count=1。sudo du -sh /var/log/*。sudo truncate -s 0 /var/log/<log_file> 或使用 logrotate 工具。df -h 或 fdisk -l。fdisk/parted 调整分区大小,或通过LVM扩展逻辑卷(需提前备份数据)。ncdu(交互式工具,安装:sudo yum install ncdu)。sudo find / -type f -size +100M。vm.swappiness)减少对交换空间的依赖。sudo systemctl stop <服务名>。注意:操作前务必备份重要数据,避免误删。