Cleaning out /var/log?

Don´t be shy, Linux is fun! =)
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Cleaning out /var/log?

Post by ayu »

I am making a small script to clean out command history in .bash_history, as well as log files in /var/log.

The thing I am wondering is though, if I just blindly clean out the whole /var/log folder, would any application break then because it can't find it's log?

Or rather, what are the risks of it?

I was thinking about something like this
find -type f -exec rm {} \;
Thanks in advance : -)
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: Cleaning out /var/log?

Post by bad_brain »

it shouldn't cause problems when you delete all log files, new files should be created automatically...but I say "shouldn't" because it depends on the applications that create the log.
the apache2.log and syslog for example are no problem, but I know Snort for example will complain about it.
so it's better to clean the log files that are in use by sending a > (like > /var/log/apache2.log).

:wink:
Image

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: Cleaning out /var/log?

Post by ayu »

Ok, thanks man ;)
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: Cleaning out /var/log?

Post by bad_brain »

btw, isn't logrotate installed on your system? you could configure it to keep logs only for 7 days for example and remove all older logs automatically:

http://linuxcommand.org/man_pages/logrotate8.html" onclick="window.open(this.href);return false;

:wink:
Image

trickb0x
forum buddy
forum buddy
Posts: 18
Joined: 22 Dec 2010, 08:16
13

Re: Cleaning out /var/log?

Post by trickb0x »

Deleting /var/log can certainly break a number of things on your system (learned this the hard way). Try this command, which will empty the files instead of deleting them:

sudo find /var/log -maxdepth 5 -type f -exec bash -c "echo -n '' > {}" \;&

Post Reply