Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 0 down vote accepted

If you need to truncate logs:

cd /var/log
for i in *
do test -f $i -a -s $i && > $i
done
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 at 20:43
    
@TeunVink adjusted, thanks –  yarek Apr 21 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
        fi
done

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

share|improve this answer

Your Answer

 
discard

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.