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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值