Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 line? (My admin skills leave me nervous.)

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

share|improve this question
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
up vote 11 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.

share|improve this answer
logrotate can also delete the oldest files. – Kevin M Sep 28 '10 at 12:13
Well, IMHO deleting all logs can make perfect sense in some cases. For example I want to build a Virtial Machine image to be used for new deployments. Needless to say I would like it to be a really clean system without any logs, histories, caches etc. saved. – Ivan Oct 15 '12 at 18:54
Sorry, but looking at three months old log files is archeology. If you collect logs to identify problems, then evaluate them quickly. – countermode Aug 14 '14 at 14:40
@countermode You are never in the mood for nostalgia? Like looking at the 3 month old log files thinking about good ol' times? – Broco Aug 14 '14 at 14:51

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.

share|improve this answer
I didnt realize that. good to know. +1 + changed my accept. – acidzombie24 Sep 28 '10 at 21:31
I have just done this. Wish! I had read this answer earlier – VarunAgw May 30 '15 at 18:41

I'm cloning virtual machines from a master. It makes perfect sense to clear the log on the master so that when you boot the clones you won't get the master's log. I did in tcsh:

cd /var/log
foreach ii ( `find . -type f` )
foreach? cp /dev/null $ii
foreach? end

which clears the logs but keeps the files.

share|improve this answer
This should be restricted to a use-case like you describe. – Sven Nov 9 '12 at 10:41
In bash: find /var/log/ -type f -exec cp /dev/null {} \; – gerard Jun 1 at 20:28

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.

share|improve this answer

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

share|improve this answer

Cleaning all logs on a Linux system without deleting the files:

for CLEAN in $(find /var/log/ -type f)
    cp /dev/null  $CLEAN

Samba (/var/www/samba) creates log file-names with ip addresses, for those, you may want to delete them:

for CLEAN in $(find /var/log/samba -type f)
    rm -rf $CLEAN
share|improve this answer
Useful script . – Anmol Singh Jaggi Jun 12 at 12:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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