4

Log files that get extended at the tail can be read live using tail -f command

Is there anyway to do the same with a log that gets appended at the beginning?

The man page for head doesn't help.

| |
7

TomH is correct, and also, how should head output the changes? However, if all you are looking for is a continually refreshed view of the first n lines, try

watch head file.txt

or

watch -n 1 -d head file.txt
| |
7

Well you can't "append at the beginning" of a file. The only way to achieve that affect would be to rewrite the whole file, but short of doing a text match head would have no way of knowing what had happened.

It's easy for tail as it just keeps track of the position it read up to and then keeps trying to read more bytes beyond that position.

| |
  • Using sparse files, it might be possible to prepend to a file. Still, appending is much the superior approach. – Ben Voigt Aug 17 '11 at 11:36
  • @TomH, my use case was a little different. It's not a conventional file, but the output of git reflog. I wanted a way to constantly refresh the output, so that I can keep track of what's happening. – NOLFXceptMe Aug 18 '11 at 6:28
  • This does not answer the question at all. – Rub May 12 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.