質問

I'm using tail -f to print the content of a continuously changing file. When the file is truncated it shows up like this:

blah (old)..
blah more (old)..
tail: file.out: file truncated
blah..
blah more..

This can get messy when I change the file too often so that it becomes hard to see where the file begins/ends. Is there a way to somehow clear the screen when the file is truncated so that it would show up like this?

tail: file.out: file truncated
blah..
blah more..
役に立ちましたか?

解決

You could use a perl one-liner to filter the output from tail -f

e.g.

tail -f myfile.txt 2>&1 | perl -ne 'if (/file truncated/) {system 'clear'; print} else {print}'

他のヒント

I know this is old, but another (potentially simpler) solution is:

watch -n 1 cat myfile.txt

tailf myfile.txt

this is the command tailf rather than tail -f

with this command there is no file truncated returned on the screen

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top