Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from Aug 29 '11 at 7:35

This question came from our site for professional and enthusiast programmers.

up vote 6 down vote accepted

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


watch -n 1 -d head file.txt
share|improve this answer
Thanks, Christopher. This works. – NOLFXceptMe Aug 18 '11 at 6:23

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.

share|improve this answer
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

You must log in to answer this question.

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