LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 814|回复: 2

关于tail的问题请教大家。

[复制链接]
发表于 2008-1-11 15:20:23 | 显示全部楼层 |阅读模式
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
发表于 2008-1-11 16:59:36 | 显示全部楼层
Post by hexyldog;1805673

uuu@localhost:~/test$: mv test.log test.log.1
。。。。
uuu@localhost:~/test$ vi test.log

这两个操作中的 test.log 是不同的两个文件,主要是文件的 i-node 不同(不知这样说对不对)。tail 中获得的 i-node 其实就是 mv 后的 test.log.1 的 i-node。所以,应该这样:

$ echo "abcd" >> test.log.1

这是 tail 就会将 abcd 打印出来。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-1-11 17:42:15 | 显示全部楼层
Post by kingway;1805733
这两个操作中的 test.log 是不同的两个文件,主要是文件的 i-node 不同(不知这样说对不对)。tail 中获得的 i-node 其实就是 mv 后的 test.log.1 的 i-node。所以,应该这样:

$ echo "abcd" >> test.log.1

这是 tail 就会将 abcd 打印出来。


多谢,inode 就是 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.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表