11

I need to display whole file before tracking it for a new changes, not only the last 10 lines (yep, I know it's not tail conceptually). In other words, something like cat -f would do, if it would ever existed. Tail's man doesn't give me any ideas. The only option I see right now is to somehow combine cat all but last 10 lines and tail -f output.

Any hints, please?

  • 3
    cat $f && tail -n0 -f $f comes to mind, and checking the man page it looks like tail -c0 -f $f might also do what you want (and be better because it does not create a race condition between the two processes where data written could be ignored). I don't have access to a Linux system right now but do either of those do what you want? – user Jun 03 '13 at 08:47
  • This is useful and I just added such a feature to a programming language: a "tail stream" which can read a file normally from beginnnig to end, and then goes into "tail -f" mode at the end, and can also notice that the file was replaced with a shorter one or truncated, and follow that. You need this to be able to do things like process existing logs (catch up with a backlog) and then begin processing new entries. – Kaz Nov 29 '13 at 06:26

1 Answers1

16

Here's one way to do it:

tail -f -n+0 /var/log/messages

There doesn't seem to be any difference between a +0 and a +1, so this would be equivalent:

tail -f -n+1 /var/log/messages
slm
  • 369,824
  • 3
    Relevant part of the man page (save people some typing)...

    -n, --lines=K output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth

    – demented hedgehog Feb 17 '15 at 03:27