当遇到ubuntu磁盘使用100%...

清理日志文件、系统垃圾、软件缓存、不再使用的孤立软件

怎么好像收破烂的在吆喝… … …

  1. 学习使用du -sh /* --exclude proc - > 当遇到ubuntu磁盘使用100%…
  2. 删除 *.1 *.gz文件 - > linux log 及如何清除log
  3. journal定时清理 - > Linux 系统 /var/log/journal/ 垃圾日志清理
  4. 定期清除日志脚本 - > linux 定期清除日志
# 这2个命令运行一次就行了
journalctl --vacuum-time=1w   # 只保留近一周的日志
journalctl --vacuum-size=10M  # 只保留10MB的日志

删除日志命令:

#!/bin/sh

echo ""
echo -e "\n\n\n  https://www.jianshu.com/p/ad59f4a938e9  \n\n\n"
rm -rf /var/log/*.gz
rm -rf /var/log/*.1
echo -e "------------------------------------------------------------------------\n\n"


echo ""
echo -e "\n\n\n  https://www.jianshu.com/p/b316a9b5e36a  \n\n\n"
cd /var/log
du -sh * |grep M
rm -rf /var/log/auth.log.*
rm -rf /var/log/alternatives.log.*
rm -rf /var/log/daemon.log.*
rm -rf /var/log/debug.*
rm -rf /var/log/dpkg.log.*
rm -rf /var/log/kern.log.*
rm -rf /var/log/messages.*
rm -rf /var/log/syslog.*
rm -rf /var/log/user.log.*
rm -rf /var/log/vsftpd.log.*
rm -rf /var/log/wtmp.*

rm -rf /var/log/mysql/error.log.*

rm -rf /var/log/apache2/error.log.*
rm -rf /var/log/apache2/other_vhosts_access.log.*


# dd if=/dev/null of=/var/log/auth.log
# dd if=/dev/null of=/var/log/alternatives.log
# dd if=/dev/null of=/var/log/daemon.log
# dd if=/dev/null of=/var/log/debug
# dd if=/dev/null of=/var/log/dpkg.log
# dd if=/dev/null of=/var/log/kern.log
# dd if=/dev/null of=/var/log/messages
# dd if=/dev/null of=/var/log/syslog
# dd if=/dev/null of=/var/log/user.log
# dd if=/dev/null of=/var/log/vsftpd.log
# dd if=/dev/null of=/var/log/wtmp
# dd if=/dev/null of=/var/log/mysql/error.log
# dd if=/dev/null of=/var/log/apache2/error.log
# dd if=/dev/null of=/var/log/apache2/other_vhosts_access.log

cat dev/null > /var/log/auth.log
cat dev/null > /var/log/alternatives.log
cat dev/null > /var/log/daemon.log
cat dev/null > /var/log/debug
cat dev/null > /var/log/dpkg.log
cat dev/null > /var/log/kern.log
cat dev/null > /var/log/messages
cat dev/null > /var/log/syslog
cat dev/null > /var/log/user.log
cat dev/null > /var/log/vsftpd.log
cat dev/null > /var/log/wtmp
cat dev/null > /var/log/mysql/error.log
cat dev/null > /var/log/apache2/error.log
cat dev/null > /var/log/apache2/other_vhosts_access.log
echo -e "------------------------------------------------------------------------\n\n"


echo ""
echo -e "\n\n\n  https://blog.csdn.net/zhuying_linux/article/details/6757729  \n\n\n"
cat /dev/null > /var/log/syslog
# cat /dev/null > /var/adm/sylog
cat /dev/null > /var/log/wtmp
# cat /dev/null > /var/log/maillog
cat /dev/null > /var/log/messages
# cat /dev/null > /var/log/openwebmail.log
# cat /dev/null > /var/log/secure
# cat /dev/null > /var/log/httpd/error_log
# cat /dev/null > /var/log/httpd/ssl_error_log
# cat /dev/null > /var/log/httpd/ssl_request_log
# cat /dev/null > /var/log/httpd/ssl_access_log
echo -e "------------------------------------------------------------------------\n\n"

du -sh * |grep M
# 
df -h
du -sh /* --exclude proc 

echo -e "------------------------------------------------------------------------\n\n"




清理linux系统垃圾

删除 旧版本、缓存、不使用的孤立软件 - > Linux下清除系统日志方法


其他: Debian/Ubuntu清理硬盘空间的8个技巧

  1. 清理卸载残留
# remove将会删除软件包,但会保留配置文件.purge会将软件包以及配置文件都删除.
# grep "^rc"				第一栏的rc表示软件包已经删除(Remove)
# cut -d " " -f3			提取这些软件包的名称,(-d " ": 以空格分隔) (-f3: 取第三列)
# xargs sudo dpkg --purge	删除这些软件包
# xargs 多行输入单行输出		# https://www.runoob.com/linux/linux-comm-xargs.html
# sudo dpkg --purge
dpkg --list | grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge

  1. 删除没有用的deb软件安装包
sudo apt-get autoclean -y 	#清理旧版本的软件缓存
sudo apt-get clean -y 		# 清理所有软件缓存

  1. 删除孤儿软件包
sudo apt-get autoremove -y 	# 删除系统不再使用的孤立软件

  1. 删除过时的软件包
sudo apt-get install aptitude  -y
sudo aptitude search ?obsolete| cut -d " " -f2| xargs sudo dpkg --purge

  1. 查看大容量软件包
sudo apt-get install debian-goodies -y
dpigs -H --line=20

# 这里只提供查看,不提供删除
# 因为有的包还在使用
# 不推荐这个删除。上面的步骤已经够用了


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值