Is there a proper way to clear logs?

You can use:

> /var/log/mail.log

That will truncate the log without you having to edit the file. It’s also a reliable way of getting the space back.

In general it’s a bad thing to use rm on the log then recreating the filename, if another process has the file open then you don’t get the space back until that process closes it’s handle on it and you can damage it’s permissions in ways that are not immediately obvious but cause more problems later on.

Yasar has a nice answer using truncate

Also if you are watching the contents of the log you might like to use the tail command:

tail -f /var/log/mail.log

Ctrl-C will break off the tailing.

Leave a Comment