How to do a `tail -f` of log rotated files?

On a long running system I usually have a terminal with

$ tail -f /var/log/kern.log

or something like this open.

But from time to time I have to restart such command because no new messages are displayed anymore.

I assume this is because of the log rotating job that has replaced the log file tail -f was ‘watching’.

How can I avoid this restarting issues?

Can I invoke tail such that it notices the rotating process and does the right thing?

(I notice this issue on a Ubuntu 11.04 system that uses rsyslogd by default.)

Asked By: maxschlepzig


Use the -F option instead:

tail -F /var/log/kern.log

The -F option tells tail to track changes to the file by filename, instead of using the inode number which changes during rotation. It will also keep trying to open the file if it’s not present.

Answered By: andcoz
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.