How to do a `tail -f` of log rotated files?
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.
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, 2022Comments
-
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 over 12 yearsAwesome, yes, I am. (just for the record, this is a GNU tail option - where GNU tail is of course the default on Ubuntu).
-
serb over 12 yearsYou are right :-/ I did not noticed that Ubuntu in your question was only an example.
-
maxschlepzig over 12 yearsnot 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 over 6 yearsIs
tail -F /var/log/kern.log
equivalent totail -f --follow=name --retry /var/log/kern.log
? -
andrej almost 6 years@Basj - according to man7.org/linux/man-pages/man1/tail.1.html it's equivalent