r/linux • • Mar 30 '15

Stop using tail -f (mostly)

http://www.brianstorti.com/stop-using-tail/
830 Upvotes

219 comments sorted by

View all comments

95

u/berkes Mar 30 '15

On a sidenote: I teach people to always use tail -F instead of tail -f. You won't see the difference that often. But when you do, you wish you had started with -F instead.

-F same as --follow=name --retry tail(1).

You'll see the difference when you are tailing that log file to see why the deamon crashes on restart (only to find that on restart it also rotates the logs buy deleting and re-creating: tail stops)

You'll also see the difference when you keep tail running (e.g. in screen) and on re-opening to find you have to restart it.

And mostly, you'll see this breaking when some script or tool uses tail to e.g. monitor something and have that script crash when the log is rotated (poorly).

(edit: inserted some blank lines for legibility)

14

u/rydan Mar 30 '15

I've used -F before but mostly use -f. Will -F close the file handle when the logs are rotated? Sometimes I leave a console open with -f running and the logs rotate but the disk space isn't reclaimed since there is still an open handle until I quit.

49

u/Deewiant Mar 30 '15

Will -F close the file handle when the logs are rotated?

Yes, it will: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c#n1042

11

u/isr786 Mar 30 '15

+1

The best kind of answer :)

2

u/berkes Mar 30 '15

I'm not sure about that though. I assumed following the handle meant closing the old one. But never really dove into it.