ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [20170607]tail -F.txt

[20170607]tail -F.txt

原创 Linux操作系统 作者:lfree 时间:2017-06-07 08:41:48 0 删除 编辑

[20170607]tail -F.txt

--//如果你看man tail文档,可以发现-F 与 -f 非常相似,但是存在一点点区别.

-f, --follow[={name|descriptor}]
      output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent

-F     same as --follow=name --retry


--//-F 多了一个--retry,也就是文件删除后或者被截断后依旧可以使用.通过例子来说明:

1.测试-f:
--//终端1:
$ touch a.log
$ tail -f a.log

--//终端2:
$ echo 1111 >| a.log

--//终端1:
$ tail -f a.log
1111

--//终端2:
$ echo 2222 >> a.log

--//终端1:
$ tail -f a.log
1111
2222

--//终端2:
$ echo aaaa >| a.log

--//终端1:
$ tail -f a.log
1111
2222
tail: a.log: file truncated

--//终端2:
$ echo bbbb >> a.log

--//终端1:
$ tail -f a.log
1111
2222
tail: a.log: file truncated
bbbb

--//终端2:
$ rm a.log
/bin/rm: remove regular file `a.log'? y
$ echo cccc > a.log

--//终端1:
$ tail -f a.log
1111
2222
tail: a.log: file truncated
bbbb

--//可以发现不输出cccc.

2.测试-F.
--//实际上2者的差别就在于删除文件,再加入内容后,tail -F可以显示.

--//终端1:
$ tail -F a.log
cccc

--//终端2:
$ rm a.log
/bin/rm: remove regular file `a.log'? y

--//终端1:
$ tail -F a.log
cccc
tail: `a.log' has become inaccessible: No such file or directory

--//终端2:
$ echo dddd >>a.log

--//终端1:
$ tail -F a.log
cccc
tail: `a.log' has become inaccessible: No such file or directory
tail: `a.log' has appeared;  following end of new file
dddd

--//删除文件后在建立加入内容-F可以显示.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2140374/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7971380