zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    CSS3 动画-- 鼠标移上去,div 会旋转、放大、移动
    jquery 微信端 点击物理返回按钮,弹出提示框
    H5 canvas pc 端米字格 写字板
    【三剑客】awk函数
    【三剑客】awk运算符
    【三剑客】awk命令2
    【三剑客】awk命令
    磁盘
    用户管理
    定时任务Crond
  • 原文地址:https://www.cnblogs.com/zhzhang/p/5778836.html
Copyright © 2011-2022 走看看