Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I have a script running continuously, reading tail -f /var/log/daemon.log

The problem is, when the file /var/log/daemon.log gets rotated by logrotate, tail still has "file handle" for the old (rotated) file and no longer displays the contents of the new /var/log/daemon.log file

Is there any way to fix this, so that tail shows the contents of the new file, if the file was rotated ?

share|improve this question

marked as duplicate by cuonglm, derobert, polym, slm Aug 22 at 17:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 8 down vote accepted

Yes. You're looking for tail -F instead of tail -f (that is, a capital F instead of lowercase). Check the tail(1) manpage.

Alternatively, you could use --follow=name --retry, which the man page documents as the same thing.

(These are from GNU coreutils tail. Other tails may not have this; POSIX does not specify -F, --follow, or --retry. If you have to work on those systems, I'd suggest Perl's File::Tail.)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.