Clearing Down Large Log Files in Linux Quickly

You should use something like logrotate to manage you log files however sometimes you are not interested in the log content and just want to clear them. Especially if you have multi GB files due to excessive errors. In this situation use:

> /var/log/logfile-name

This will clear the file but not remove it. It is possible that a process has locked the file, in which case track it down with:

lsof /var/log/logfile-name

Finding large files in Linux can be tricky especially if there is no X. This can help:

find /var/log/ -size +1000000k -print0 | xargs -0 ls -lh

Just change the path to the directory you are interested in, in this case where the logs are usually located.

Written on March 12, 2012