简体   繁体   English

tail -f logfile未显示新添加的条目

[英]tail -f logfile is not showing the newly added entries

I have a log file contents of log.file are 我有一个log.file的日志文件内容

123
123
321
312
123
412
151

I have done tail -f log.file . 我做了tail -f log.file In other session, I have opened the same log file and appended more values. 在其他会话中,我打开了相同的日志文件并附加了更多值。 my assumption is that tail -f log.file should show the newly appended values but its not showing. 我的假设是tail -f log.file应显示新附加的值,但不显示。

That depends on how you open the file and append. 这取决于您打开文件和追加的方式。 You have to make sure the change happens "in place" 你必须确保“就地”发生变化

This will work: 这将有效:

echo >> logfile

This won't: 这不会:

vi logfile

Why not? 为什么不? vi is equivalent to: vi相当于:

mv logfile logfile~
echo >> logfile

After this sequence of commands, tail -f will follow logfile~ ; 在这个命令序列之后, tail -f将遵循logfile~ ; it won't see the newly created file. 它不会看到新创建的文件。

This happens because tail doesn't follow the name; 这是因为tail不遵循名称; it follows the file descriptor which doesn't change when the name changes. 它遵循文件描述符,当名称更改时,该描述符不会更改。 This approach allows Unix all kinds of neat tricks (like echo appending to the file while tail has it open). 这种方法允许Unix各种巧妙的技巧(比如echo附加到文件,而tail打开它)。

tail -F would work since it notices that the file was renamed. tail -F会工作,因为它注意到文件已重命名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM