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