Hi all!
Do you know the difference between “tail -f” and “tail -F”?
Ok, don’t feel bad. It’s very difficult to find someone who knows… And with a reason, I can’t find any link explaining this by Googling.
It’s possible that I don’t know how to search it too. But I searched as I’d search if I didn’t know that… And couldn’t find anything about…
Let’s take a look on –help, so:
[root@mbdbasrvr]# tail --help Mandatory arguments to long options are mandatory for short options too. --retry keep trying to open a file even if it is inaccessible when tail starts or if it becomes inaccessible later; useful when following by name, i.e., with --follow=name -f, --follow[={name|descriptor}] output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent -F same as --follow=name --retry -n, --lines=N output the last N lines, instead of the last 10 --max-unchanged-stats=N with --follow=name, reopen a FILE which has not changed size after N (default 5) iterations to see if it has been unlinked or renamed (this is the usual case of rotated log files) If the first character of N (the number of bytes or lines) is a `+', print beginning with the Nth item from the start of each file, otherwise, print the last N items in the file. N may have a multiplier suffix: b 512, k 1024, m 1024*1024. With --follow (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will continue to track its end. This default behavior is not desirable when you really want to track the actual name of the file, not the file descriptor (e.g., log rotation). Use --follow=name in that case. That causes tail to track the named file by reopening it periodically to see if it has been removed and recreated by some other program. Report bugs to .
(Yes, I cutted off non useful options. But you can check in your SO, if want to verify all options.)
So, ok! The information is there, but isn’t very clear. You have to match some points to understand it. I can’t find examples using -F nor –retry… So, let’s innovate posting about it… 🙂
The effect of F (capital) is the same of “-f file_name –retry”. It basically “still working” if the inode of the file change. Is very useful to systems with log rotation or stuffs like that.
Let me show you:
Session1:
[root@mbdbasrvr]# echo "test1">test.log
Session2:
[root@mbdbasrvr]# tail -f test.log test1
Session1:
[root@mbdbasrvr]# echo "test2">test.log
Session2:
[root@mbdbasrvr]# tail -f test.log test1
oook, we truncated the file but the tail didn’t change. But if a use an appen by now?
Session1:
[root@mbdbasrvr]# echo "test2">>test.log [root@mbdbasrvr]# echo "test3">>test.log [root@mbdbasrvr]# cat test.log test2 test2 test3
Session2:
[root@mbdbasrvr]# tail -f test.log test1 <> [root@mbdbasrvr]# tail -f test.log test2 test2 test3
Still not working, unless you restart the command… It’s because inode changed.
Let’s do it with -F (capital), to see the difference:
Session1:
[root@mbdbasrvr]# mv test.log oldtest.log [root@mbdbasrvr]# echo "new_test">test.log
Session2:
[root@mbdbasrvr]# tail -F test.log new_test
Session1:
[root@mbdbasrvr]# echo "new_test2">>test.log
Session2:
[root@mbdbasrvr]# tail -F test.log new_test new_test2
Session1:
[root@mbdbasrvr]# echo "new_test3">test.log [root@mbdbasrvr]# echo "new_test4">>test.log
Session2:
[root@mbdbasrvr]# tail -F test.log new_test new_test2 tail: test.log: file truncated new_test3 new_test4
Session1:
[root@mbdbasrvr]# mv test.log oldtest.log mv: overwrite `oldtest.log'? y [root@mbdbasrvr]# echo "new_test_with_capital">>test.log [root@mbdbasrvr]# rm test.log [root@mbdbasrvr]# echo "xxx new file">test.log
Session2:
[root@mbdbasrvr]# tail -F test.log new_test new_test2 tail: test.log: file truncated new_test3 new_test4 tail: `test.log' has become inaccessible: No such file or directory tail: `test.log' has appeared; following end of new file new_test_with_capital tail: `test.log' has become inaccessible: No such file or directory tail: `test.log' has appeared; following end of new file xxx new file
Owoooooow! Cool, hãn?
Even we truncate, or move, or remove and recreate it, the command still working! 🙂
Very cool and very useful to some situations… Unfortunately just a few know it… :/
Let’s spread this information by sharing this post?
Have a nice day, see ya!
Matheus.