linux tail -f 和 tail -F的區別 && tail 的斷點續傳


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM