Delete logs in "/var/log"? -SOLVED

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
WHVW
Level 5
Level 5
Posts: 678
Joined: Tue May 19, 2015 4:31 pm

Delete logs in "/var/log"? -SOLVED

Post by WHVW »

In another post, Flemur had mentioned accumulating log files in "/var/log". Are they all safely delete-able? Even the compressed .gz ones?
Thanks.
Last edited by WHVW on Fri Feb 02, 2018 12:43 am, edited 1 time in total.
User avatar
trytip
Level 13
Level 13
Posts: 4855
Joined: Tue Jul 05, 2016 1:20 pm

Re: Delete logs in "/var/log"?

Post by trytip »

i delete all logs BUT i don't delete the folders. many say leave logs alone but i don't need them. i delete them maybe weekly. bleachbit admin mode has a very clean way of using logrotate to delete logs but keep the current so it's more like trimming the logs.
Image
User avatar
jimallyn
Level 18
Level 18
Posts: 8955
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Delete logs in "/var/log"?

Post by jimallyn »

WHVW wrote:Are they all safely delete-able? Even the compressed .gz ones?
I would think the .gz ones would be the most safely delete-able, as those are old and they get zipped up when there are new ones.
Image

“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
User avatar
Flemur
Level 18
Level 18
Posts: 8650
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Delete logs in "/var/log"?

Post by Flemur »

WHVW wrote:In another post, Flemur had mentioned accumulating log files in "/var/log". Are they all safely delete-able? Even the compressed .gz ones?
Thanks.
The .gz files are old ones - they're definitely safe to delete unless you have some reason to look at old log files.

This little script deletes old log files in /var/log and in its sub-dirs too:
clear_log.sh

Code: Select all

#!/bin/sh
find /var/log -type f -name "*.old" -exec rm -f {} \;
find /var/log -type f -name "*.gz" -exec rm -f {} \;
find /var/log -type f -name "*.1" -exec rm -f {} \;
Edit: as for deleting the current log files, that may or may not be safe but it also shouldn't make much difference in disk space unless you have an recurring error msg that's filling up a file.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
User avatar
all41
Level 16
Level 16
Posts: 6346
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Delete logs in "/var/log"?

Post by all41 »

This 17.3 Mate system was installed 4/30/2016 and /var/log directory is 16.8 mb.
If your log files are rapidly increasing in size then you may have issues causing errors to be continually logged.
Light travels faster than sound.
That's why some people appear smart until you hear what they are saying.
WHVW
Level 5
Level 5
Posts: 678
Joined: Tue May 19, 2015 4:31 pm

Re: Delete logs in "/var/log"? -SOLVED

Post by WHVW »

Ran Flemur's scripts which took care of the problem. There were no huge, growing files but many little ones that had accumulated over the years.
Thanks, and thanks for all the other info too.
User avatar
Termy
Level 5
Level 5
Posts: 776
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Delete logs in "/var/log"? -SOLVED

Post by Termy »

I strongly recommend you leave them alone; they're there for a reason. I guess the .gz ones could be removed, if you want to be particularly anal about it, but even I won't remove them, and believe me when I say, I'm very anal about how my system is set up! xD
Here to help.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/channel/UCfp-lN ... naEE6NtDSg
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife
lmuserx4849

Re: Delete logs in "/var/log"? -SOLVED

Post by lmuserx4849 »

I didn't see it mentioned, but syslog logrotate configuration file is in /etc/logrotate.d/rsyslog. And the running of logrotate is controlled by cron.daily. So in theory, if you like how many and the size, you shouldn't have to do anything. In fact, all log files should be handled this way. Check out /etc/logrotate.d directory.

I changed my rsyslog file to be monthly, rotate 12, dateext. So my log archives look like this: syslog-20180101.gz. I always have 12 months. No more. No less. All the sizes should be pretty much the same, if not, I can view it and compare months to see what was going on.

I don't know how systemd changed any of this. The log under systemd is just one huge binary file.
User avatar
Termy
Level 5
Level 5
Posts: 776
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Delete logs in "/var/log"? -SOLVED

Post by Termy »

That's awesome! Nice one. I'll do that too. :) Like this, for each block?
.lmscrot.jpg
.lmscrot.jpg (8.93 KiB) Viewed 5202 times
I corrected the 'daily' bit to show 'monthly'.
Here to help.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/channel/UCfp-lN ... naEE6NtDSg
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife
Post Reply

Return to “Software & Applications”