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?

2
  • 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
    Commented Jun 3, 2013 at 8: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
    Commented Nov 29, 2013 at 6:26

1 Answer 1

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
1
  • 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 Commented Feb 17, 2015 at 3:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .