[Novalug] 'tail --follow=name filename' to keep tailing the file even if it's recreated (such as due to log rotation)

Paul W. Frields stickster at gmail.com
Fri Mar 6 15:26:07 EST 2009


On Fri, Mar 06, 2009 at 01:55:02PM -0500, Jon LaBadie wrote:
> On Fri, Mar 06, 2009 at 01:33:40PM -0500, Doug Toppin wrote:
> > one of the bad things (if there are really any bad things about it)
> > about using unix/linux for so long is that it's easy to not go back
> > and browse the man pages every now and then to notice improved command
> > arguments.  i keep tail running on a tomcat log file on my desktop.
> > each night log rotation goes and moves it causing a new one to get
> > created.  if you use 'tail -f name', tail will not "see" the new file
> > and just sit there forever looking at the old file.
> > i noticed from 'man tail' that there is a '--follow=name' argument
> > that tells tail to re-open the file every now and then in case it gets
> > deleted/recreated.
> > 
> > an example usage is:
> > tail --follow=name filename
> > 
> > i just thought that i'd pass it along in case anyone else has been
> > ruthlessly killing and restarting tail every day like i've been for
> > weeks.
> 
> They also dropped (in Fedora 9 I believe) an old option that I
> regularly used.  Tail, by default, outputs the last 10 lines.
> The original UNIX tail accepted a +/-# option to either output
> a different number of the ending lines (ex -3 for just 3 lines)
> or starting with a particular line number (ex +2 to skip the
> first line and start with line 2).
> 
> SUS (The Single Unix Specification) dropped this option in
> favor of "-n #" where # can be signed as above.  But most
> linux tails still supported the original +/-# notation
> even though it was not on the man page.
> 
> Fedora's tail still supports -#, but no longer supports +#.

Actually, this wasn't a Fedora change, it was a change in the upstream
coreutils package -- to meet POSIX standards, if I recall correctly.
The proper way to do this now:

tail -n +# <file>

-- 
Paul W. Frields                                http://paul.frields.org/
  gpg fingerprint: 3DA6 A0AC 6D58 FEC4 0233  5906 ACDB C937 BD11 3717
  http://redhat.com/   -  -  -  -   http://pfrields.fedorapeople.org/
  irc.freenode.net: stickster @ #fedora-docs, #fedora-devel, #fredlug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://calypso.tux.org/pipermail/novalug/attachments/20090306/73c0695c/attachment.bin 


More information about the Novalug mailing list