Continuously monitor logs with tail that are occasionally rotated

Ah, there's a flag for this.

instead of using tail -f /var/log/file we should be using tail -F /var/log/file


tail -F translates to tail --follow=name --retry as in;

  • --follow=name: follow the name of the file instead of the file descriptor
  • --retry: if the file is inaccessible, try again later instead of dying

# tail --follow=mylog.log

From man tail:

With --follow (-f), tail defaults to  following  the  file  descriptor,
       which  means that even if a tail’ed file is renamed, tail will continue
       to track its end.  This default behavior  is  not  desirable  when  you
       really want to track the actual name of the file, not the file descrip‐
       tor (e.g., log rotation).  Use --follow=name in that case.  That causes
       tail  to track the named file by reopening it periodically to see if it
       has been removed and recreated by some other program.

So in this case using the -F option would be correct.

-F     same as --follow=name --retry

The exact answer depends on your OS - but in many cases, tail -F will do the right thing.


tail -F or tail --follow=name