Can i delete everything in /var/log? or should i only delete files (recursively) in /var/log but leave folders?

Does anyone have a good rm command? (my admin skills leave me nervous)

Note: I am using debian. I am not sure what version

link|improve this question

50% accept rate
1  
Deleting log files is a bad idea (you'll also need to find every running process that has it's own log file and "kill -HUP" it, a soft restart that will result in the program recreating any necessary log files). I would strongly advise against deleting log files, rely on utilities like logrotate to manage the contents of /var/log for you automatically (it does stuff like HUP the processes) If I may I'd like to tackle this from a different angle. What problem are you trying to resolve that's led you to consider this? – Twirrim Sep 29 '10 at 17:34
feedback

4 Answers

up vote 6 down vote accepted

Instead of deleting the files you should rotate them, e. g. using logrotate.

You never know when you'll actually need the logs from some time ago, so it's better to archive them (up to a reasonable age, e. g. 3 months).

logrotate can compress your old log files so they don't occupy a lot of disk space.

link|improve this answer
2  
logrotate can also delete the oldest files. – Kevin M Sep 28 '10 at 12:13
feedback

Delete all files:

find /var/log -type f -delete

Delete all .gz and rotated file

find /var/log -type f -regex ".*\.gz$"
find /var/log -type f -regex ".*\.[0-9]$"

Try run command without "-delete", to test it.

link|improve this answer
feedback

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!!!".

As joschi has pointed out, there is no reason to do this. I have debian servers running that haven't had a single log file deleted in years.

link|improve this answer
I didnt realize that. good to know. +1 + changed my accept. – acidzombie24 Sep 28 '10 at 21:31
feedback

You can use the option ctime to find old files... for example:

find -ctime +30

As bindbn explain, first try the find fetch files and after use the option delete :D

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.