Skip to content
Advertisement

Tailing a file from where I left off before?

Suppose I have a file. I tail its last 10 lines and got some data. And the next time I come to tail, its length increases by 4. So I need to tail only that many lines to get data. Is there a simple command line for this? Like a mix of tail, wc, and grep?

Advertisement

Answer

If you save the size of the file when you close tail, you can do tail -c +[previous size]. This starts at a specific byte offset of the file instead of a number of lines from the end. This may be subject to a race condition if the size changes between when you close the first tail process and when you measure the size.

Why are you closing and reopening the tail command, instead of just using the -f option and continuing reading?

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement