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

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
tail: mylog.log: file truncated

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

You must log in to answer this question.

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