what happened when we remove all files and folders in ubuntu from /var/log folder

Delete all of /var/log?

If you delete everything in /var/log, you will most likely end up with tons of error messages in very little time, since there are folders in there which are expected to exist (e.g. exim4, apache2, apt, cups, mysql, samba and more). Plus: there are some services or applications that will not create their log files, if they don’t exist. They expect at least an empty file to be present. So the direct answer to your question actually is “Do not do this!!!”.

How to clean log files in Linux

1.Check the disk space from the command line. Use the du command to see which files and directories consume the most space inside of the /var/log directory.

$ sudo du -h /var/log/

The du command prints the estimated disk space usage of each file and directory for the path that you specified.

The -h argument causes the command to print the information in a human-readable format.

The output of the du command  :

$ sudo du -h /var/log/

4.0K /var/log/landscape
196K /var/log/apt
80M /var/log/apache2
12K /var/log/dbconfig-common
4.1G /var/log/journal/ec2d37b34f2f9fd221dd8855017d9f76
4.1G /var/log/journal
du: cannot read directory ‘/var/log/amazon/ssm/audits’: Permission denied
4.0K /var/log/amazon/ssm/audits
208K /var/log/amazon/ssm
212K /var/log/amazon
4.0K /var/log/lxd
4.0K /var/log/dist-upgrade
36K /var/log/mysql
152K /var/log/unattended-upgrades
4.5G /var/log/

List Disk Usage of current directory

 $ du -h *

After finding that my /var/log/journal folder was taking several GB, I followed:

$ sudo journalctl --vacuum-time=10d

which cleared 90%+ of it

Leave a Reply