bash-1中啟動如下進程
while [ "true" ] ; do date >> test.log; sleep 1 ; done;
bash-2中,
tail -f test.log
bash-3中,
tail -F test.log
bash-4中,
rm test.log;或者mv test.log testlog1
1.看bash-2,屏幕停止顯示log;
2.看bash-3,屏幕上依然在繼續輸出test.log的內容
tail -F 適用於比如日志定期mv的情況(例如按天或者按小時mv query_log query_log1的情況)
【參考】https://www.douban.com/note/85851188/
-------------------------------------------------------------------------------------------
tail實現斷點續傳功能
tail -n +$(tail -n1 num) -F test.log 2>&1 | awk 'ARGIND==1{i=$0;next}{i++;if($0~/^tail/){i=0};print $0;print i >> "num";fflush("")}' num -
【參考】http://blog.itpub.net/22569416/viewspace-1976065
如果文件在斷點的時候,經過mv或者rm操作,也能正常
【經過mv操作 輸出多出兩行】
tail: `test.log' has become inaccessible: No such file or directory
tail: `test.log' has appeared; following end of new file
【經過rm操作 輸出多出一行】
tail: `test.log' has become inaccessible: No such file or directory
但如果tail卡住或者不運行,但是文件又被rm或者mv過,則會丟失數據。!!!
【參考】http://blog.itpub.net/22569416/viewspace-1976065
