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

47,734

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.

Share:
47,734
maxschlepzig
Author by

maxschlepzig

My name is Georg Sauthoff. 'Max Schlepzig' is just a silly old pseudonym (I am hesitant to change it because existing @-replies will not be updated) I studied computer science In my current line of work, I work on trading system software and thus care about low-latency

Updated on September 18, 2022

Comments

  • maxschlepzig
    maxschlepzig over 1 year

    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.)

  • maxschlepzig
    maxschlepzig over 12 years
    Awesome, yes, I am. (just for the record, this is a GNU tail option - where GNU tail is of course the default on Ubuntu).
  • serb
    serb over 12 years
    You are right :-/ I did not noticed that Ubuntu in your question was only an example.
  • maxschlepzig
    maxschlepzig over 12 years
    not a problem at all - I just commented for completeness (sometimes I just want to look what is POSIX and what is not). The question was indeed pretty much about Ubuntu.
  • jiffy.of.eternity
    jiffy.of.eternity over 6 years
    Is tail -F /var/log/kern.log equivalent to tail -f --follow=name --retry /var/log/kern.log?
  • andrej
    andrej almost 6 years
    @Basj - according to man7.org/linux/man-pages/man1/tail.1.html it's equivalent