Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Aug 29 '11 at 7:35

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

add comment

2 Answers

up vote 4 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

or

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

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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