I have a log that should have the latest N entries. There's no problem if the file is a bit bigger a few times.
My first attempt is periodically running:
tail -n 20 file.log > file.log
Unfortunately, that just empties the file. I could:
tail -n 20 file.log > .file.log; mv .file.log file.log
However, that seems messy. Is there a better way?