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

What is the easiest way to clear all the /var/log/ logs so that it just looks like a fresh system? I know that the fresh system also have logs, but I don't acctualy need the old ones....

share|improve this question
up vote 1 down vote accepted

If you need to truncate logs:

cd /var/log
for i in *
do test -f $i -a -s $i && > $i
share|improve this answer
I can't do a 1 character edit, so I'll post it as a comment: the correct path is /var/log in the first line. – Teun Vink Jan 3 '14 at 20:43
@TeunVink adjusted, thanks – yarek Apr 21 '14 at 12:44

This is a bit old now but I came up with a slightly more robust solution based on yarek's answer. First it will go through and delete all of the logs that were rotated out by logrotate (eg: dmesg.2.gz, auth.log.1, etc.) then it will recurse through /var/log/ for logfiles and clear them.

rm -rfv /var/log/{*.[0-9],*.[0-9].gz}
for i in `find /var/log/ -type f`; do
        if [ -f $i ] && [ -s $i ]; then
                echo "" > $i

I've found this very useful when prepping a live system for creating a live image.

share|improve this answer

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.