免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2217 | 回复: 9
打印 上一主题 下一主题

关于tail的问题请教大家。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-11 14:58 |只看该作者 |倒序浏览
uuu@localhost:~/test$ touch test.log
uuu@localhost:~/test$ vi test.log

写入 1234 存盘退出

另开一终端uuu@localhost:~/test$tail -f test.log

此时显示的是1234


然后

uuu@localhost:~/test$: mv test.log test.log.1
uuu@localhost:~/test$ touch test.log
uuu@localhost:~/test$ vi test.log
写入 abcd 存盘退出
uuu@localhost:~/test$ ll
total 8
-rw-r--r-- 1 uuu root 15 2008-01-11 14:47 test.log
-rw-r--r-- 1 uuu root 29 2008-01-11 14:47 test.log.1

此时切换到tail窗口,发现内容并没有变化。为什么呢?

需要C-c 在重新tail -f  test.log 才能看到期望的 abcd

[ 本帖最后由 hexyldog 于 2008-1-11 15:01 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-01-11 15:38 |只看该作者
tail不是实时的。。

论坛徽章:
0
3 [报告]
发表于 2008-01-11 15:42 |只看该作者
当你执行 uuu@localhost:~/test$: mv test.log test.log.1 这个语句时,另一个终端的界面实际上已经被终止了!

论坛徽章:
0
4 [报告]
发表于 2008-01-11 15:48 |只看该作者
确实tail -f 在查看挂在后台程序所输出结果的时候是实时的。比如看日志文件的时候。
但是你可以试看看:你创建一个文件,然后一个终端tail来看这个文件,然后用另外一个终端来修改他里面的内容时,用tail查看的终端并没有实时的刷新文件。
希望有哪个高手能帮忙解答看看 tail 何时是属于实时刷新内容的!

论坛徽章:
0
5 [报告]
发表于 2008-01-11 17:12 |只看该作者

回复 #4 yingweixu 的帖子

多谢两位关注。问题解决了

默认是根据 file descriptor检索的。

-F 参数可以解决

tail --help

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

With  --follow  (-f), tail defaults to following the file descriptor, which means that even if a tail'ed file is renamed, tail will
       continue to track its end.  This default behavior is not desirable when you really want to track the actual name of the  file,  not
       the  file  descriptor (e.g., log rotation).  Use --follow=name in that case.  That causes tail to track the named file by reopening
       it periodically to see if it has been removed and recreated by some other program.

论坛徽章:
0
6 [报告]
发表于 2008-01-11 17:19 |只看该作者
原帖由 hexyldog 于 2008-1-11 17:12 发表
多谢两位关注。问题解决了

默认是根据 file descriptor检索的。

-F 参数可以解决


tail --help

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

With  --follow  (-f), tail defaults  ...



不错!

论坛徽章:
0
7 [报告]
发表于 2008-01-11 17:21 |只看该作者
个人认为 i 节点变化了!

论坛徽章:
0
8 [报告]
发表于 2008-01-11 17:42 |只看该作者
原帖由 int3 于 2008-1-11 17:21 发表
个人认为 i 节点变化了!


请问一下

inode 就是指 file descriptor 吗?

那我用-F参数是否会带来其他问题啊?

目前看没什么问题,基本实现了我要的功能。我现在很担心会不会带来什么副作用。

论坛徽章:
0
9 [报告]
发表于 2008-01-13 09:57 |只看该作者
tail -F 也不是万能的,有一个问题:
比如在tail -F A 时, 若此时读到第10行,这个时候你将一个超过10行的文件B替换A: mv B A
那么,就直接从文件B的第11行开始读,跳过文件B的前10行,而不是从新文件的开头开始读。

论坛徽章:
0
10 [报告]
发表于 2008-01-14 09:37 |只看该作者
收下了,感谢ing~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP