2012-10-08 28 views
8

我使用tail -f來打印連續更改文件的內容。當文件被截斷它顯示是這樣的:使用`tail -f`截斷文件時清除屏幕

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

這會導致混亂,當我更改文件往往使其變得難以看到文件開始/結束。有沒有辦法以某種方式clear屏幕截斷文件,以便它會顯示像這樣?

tail: file.out: file truncated 
blah.. 
blah more.. 
+0

爲什麼收票? – none

回答

9

你可以使用一個perl單行到輸出從tail -f

例如過濾

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

很好,謝謝.. – none

+0

好聽:-) – Benj

1

tailf myfile.txt的

這是命令tailf而不是尾-f

使用該命令沒有被截斷返回的屏幕上

+0

這不會從屏幕上清理舊內容,因爲我想。無論如何,Benj的答案工作,謝謝.. – none

+0

對不起,我的壞看到最初明確,然後一邊看着它完全忘記了典型的一天結束的錯誤:)高興你有它按要求工作 – Vahid

12

我知道這是舊文件,但另一種(可能更簡單的)解決方案是:

watch -n 1 cat myfile.txt

+0

+1,這實際上是什麼我這些日子一直在使用。不記得我在哪裏得到這個.. – none