I'm using tail -f
to print the content of a continuously changing file. When the file is truncated it shows up like this:
我使用tail -f来打印一个不断变化的文件的内容。当文件被截断时,它会像这样显示:
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..
3 个解决方案
#1
9
You could use a perl
one-liner to filter the output from tail -f
您可以使用perl一行程序来过滤tail -f的输出。
e.g.
如。
tail -f myfile.txt 2>&1 | perl -ne 'if (/file truncated/) {system 'clear'; print} else {print}'
#2
12
I know this is old, but another (potentially simpler) solution is:
我知道这是旧的,但另一个(可能更简单的)解决方案是:
watch -n 1 cat myfile.txt
观察-n 1 cat myfile.txt。
#3
1
tailf myfile.txt
tailf myfile.txt
this is the command tailf rather than tail -f
这是命令尾部,而不是尾部-f。
with this command there is no file truncated returned on the screen
有了这个命令,就不会在屏幕上返回文件截断。
#1
9
You could use a perl
one-liner to filter the output from tail -f
您可以使用perl一行程序来过滤tail -f的输出。
e.g.
如。
tail -f myfile.txt 2>&1 | perl -ne 'if (/file truncated/) {system 'clear'; print} else {print}'
#2
12
I know this is old, but another (potentially simpler) solution is:
我知道这是旧的,但另一个(可能更简单的)解决方案是:
watch -n 1 cat myfile.txt
观察-n 1 cat myfile.txt。
#3
1
tailf myfile.txt
tailf myfile.txt
this is the command tailf rather than tail -f
这是命令尾部,而不是尾部-f。
with this command there is no file truncated returned on the screen
有了这个命令,就不会在屏幕上返回文件截断。