解决Ubuntu体积越来越大的问题

来源:互联网 发布:战网传输数据遇到问题 编辑:程序博客网 时间:2024/04/29 00:31


我们通过删除系统的各种日志的方式来解决这个问题。

注意:虽说是删除,但你却不能以下面的命令:

rm -f logfile

其中命令中的logfile代表要删除的日志,参数 -f 表示强制删除。

为什么不能用上述命令呢?因为相关软件已经打开了它们,直接删除造成的不良后果有:

1.应用无法正确释放日志文件和写入2.显示磁盘空间未释放正确的方式:

cat /dev/null > logfile 

其中 /dev/null代表空,cat命令和符号>一起,表示将logfile置为空。

现在你明白思路了吧。

好,我们把一批这样的命令做成可执行文件,来将一批日志文件置为空。

新建myClearLogfile.sh文件内容如下:

#!/bin/shcat /dev/null > /var/log/syslogcat /dev/null > /var/adm/sylogcat /dev/null > /var/log/wtmpcat /dev/null > /var/log/maillogcat /dev/null > /var/log/messagescat /dev/null > /var/log/openwebmail.logcat /dev/null > /var/log/maillogcat /dev/null > /var/log/securecat /dev/null > /var/log/httpd/error_logcat /dev/null > /var/log/httpd/ssl_error_logcat /dev/null > /var/log/httpd/ssl_request_logcat /dev/null > /var/log/httpd/ssl_access_log

然后将此文件可执行化:

chmod a+x  myClearLogfile.sh

执行命令:

./myClearLogfile.sh


0 0