Simple command to reset / clear all logs?

Polytropon freebsd at
Wed Jan 12 19:58:07 UTC 2011

On Wed, 12 Jan 2011 20:50:04 +0100, Redd Vinylene <reddvinylene at> wrote:
> Will the logs automatically create themselves?

Usually not, but it depends on the logging mechanism. If a 
program continuously re-opens the file (after closing it)
in APPEND mode, it should be created if non-existent. But
if the program keeps the file open and just writes to it,
it can cause trouble. Good programs check the return code
of the writing operation and signal an error. Bad programs
don't do that, they just keep writing to nowhere. :-)

> I mean, I picture I have to
> manually touch a lotta them in order to avoid "cannot find" error messages?

This should be the safest method for most purposes. But as
I mentioned, just trim down the files to zero length, so they
keep present, and all writing processes (re-opening APPEND or
contunuously keep writing) shouldn't notice that.

# for FILE in /var/log/*; do cat /dev/null > ${FILE}; done

That would be better than my first suggestion. You can exchange
the part "/var/log/*" for any `find ...` command that specifies
the intended target(s) of your operation better than the builtin
shell expansion of the * expression.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list