Search code examples
syslogubuntu-20.04

syslog and kern.log files are massive


I got a warning that my PC was running out of space and noticed that /var/log had taken up nearly 190 Gb. On further inspection, noticed that the kern.log and syslog files are massive, after running du -sh *|grep G

Currently running Ubuntu 20.04.

What is the reason for this and is it safe to delete these log files?

Screenshot of log file sizes


Solution

  • Simple steps to clean and create both syslog and kern.log

    Create a sh file eg. refresh.sh and save the following code.

    echo "" > /var/log/kern.log
    echo "" > /var/log/syslog
    service syslog restart
    journalctl --vacuum-size=50M
    

    run it as root eg. sudo sh refresh.sh

    It will clear the logs from

    /var/log/syslog
    /var/log/kern.log
    /run/log/journal