linux清理磁盘

手动删除

查看挂载磁盘空间

df -h

查看根目录文件夹的大小并逆序排列

du -sh / | sort -rn

进入到大的文件夹,再进行文件排序

du -sh * | sort -rn
du -sh * | sort -rn | head -n 5       如果只想显示前5个大文件可以这样

找到大的日志文件,删除

rm -rf bigfile

redis的日志文件需要置空的方法删除

echo '' > file.log

脚本删除

1、编写清理日志脚本clearlogbefore5days.sh

#!/bin/sh
find   /opt/log  -mtime +30  -name "*.log" -exec rm {} ;

2、给脚本授权

chmod  +x  clearlogbefore5days.sh

3、加入定时执行任务

crontab -e

在最后加入:00 2 * * *  root   /home/slynux/clearlogbefore5days.sh
原文地址:https://www.cnblogs.com/soymilk2019/p/12803963.html