0

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

1

If you need to truncate logs:

cd /var/log
for i in *
do test -f $i -a -s $i && > $i
done
1
  • 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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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