Ubuntu 和 Debian 服务器磁盘空间优化
磁盘空间不大的 Ubuntu 服务器经常就会出现磁盘空间不足,下面给出一些优化磁盘空间的方法:
首先查看磁盘使用情况
bash
# 查看磁盘使用情况
df -h
# 查看具体目录占用空间
du -sh /*清理不必要的文件
bash
# 清理apt缓存
sudo apt clean
sudo apt autoremove
# 清理旧的日志文件
sudo find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
sudo journalctl --vacuum-time=7d查找和删除大文件
bash
# 查找大于100MB的文件
sudo find / -type f -size +100M -exec ls -lh {} \;
# 查找指定天数前的文件
sudo find /path/to/directory -type f -mtime +30 -delete清理Docker相关:
bash
# 清理未使用的Docker镜像和容器
docker system prune -a清理软件包:
bash
# 删除旧版本的内核
dpkg -l | grep linux-image
sudo apt remove linux-image-[旧版本号]