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.

Using tail -F to follow a file that might not exist yet, and it works across truncations, as follows:

tail: cannot open `mylog.log' for reading: No such file or directory
tail: `mylog.log' has appeared;  following end of new file
run1
run1
run1
tail: mylog.log: file truncated
run2
run2
run2

I only want to see the current run's output, as multiple runs fit in a screen and it's hard to tell where one stops and the next begins. Before executing a run, I find myself using

rm mylog.log; clear && tail -F mylog.log

But I have to remember to do that before every run. I realize that if tail would clear the screen when truncation occurs, it would give me exactly the behavior that I want without requiring any interaction from me.

The tail man page didn't seem to indicate this was possible. I'm sure I can't be the first to desire this behavior, has anyone else used other means to accomplish it?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

This snippet will work:

tail -F $LOGFILE 2>&1 | sed -e "$(echo -e "s/^\(tail: .\+: file truncated\)$/\1\e[2J/")"
share|improve this answer
1  
Interesting, I hadn't thought of piping the output of a long-running program through sed. Looks like that works, thanks! –  Jason Viers Nov 23 '10 at 18:36
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.