I never used tail -F
command instead always used tail -f
however someone told me that -F
is better without much explanation.
I looked up man page for tail command.
-f output appended data as the file grows;
-F Same as --follow=name --retry
--retry Keep trying to open a file even when it is or becomes inaccessible
It is easy to understand what lower -f
does but I do not follow what upper case -F
is trying to do. I'd appreciate someone can explain to me the differences.
Best Answer
You describe the GNU
tail
utility. The difference between these two flags is that if I open a file, a log file for example, like this:... and if the log rotation facility on my machine decides to rotate that log file while I'm watching messages being written to it ("rotate" means delete or move to another location etc.), the output that I see will just stop.
If I open the file with
tail
like this:... and again, the file is rotated, the output would continue to flow in my console because
tail
would reopen the file as soon as it became available again, i.e. when the program(s) writing to the log started writing to the new/var/log/messages
.On the free BSD systems, there is no
-F
option, buttail -f
will behave liketail -F
does on GNU systems, with the difference that you get the messagein the output when the file you're monitoring disappears and reappears.
YOU CAN TEST THIS
In one shell session, do
That will now wait for you to type stuff. Just go ahead and type some gibberish, a few lines. It will all be saved into the file
myfile
.In another shell session (maybe in another terminal, without interrupting the
cat
):This will show the (end of the) contents of
myfile
in the console. If you go back to the first shell session and type something more, that output will immediately be shown bytail
in the second shell session.Now quit
cat
by pressing Ctrl+D, and remove themyfile
file:Then run the cat again:
... and type something, a few lines.
With GNU
tail
, these lines will not show up in the second shell session (wheretail -f
is still running).Repeat the exercise with
tail -F
and observe the difference.