On BSD systems (and I believe most other systems) tail -f
will reset to the beginning of the file if it sees that the file has been truncated (this sounds like exactly the behavior you want).
On Linux systems the same thing happens, but at least on the Debian box I have laying around tail has a "polling interval", so you need to tell it not to sleep between checks of the file (tail -s 0 -f ...
) for it to notice the truncation, otherwise strange things happen (if the file is the same size or smaller when it's written out you get no output, if it's bigger you get everything after tail's current byte-count marker, etc. -- Play with your tail impementation to see how it behaves)
As an alternative on both Linux and BSD systems tail has a -F
option (which is like -f
but checks to see if the file has been rotated -- i.e. the name points to a different inode number). This won't help you if the file is being truncated as opposed to unlink'd and replaced though.