0

I am trying to watch my log file with less --follow-name +F MyLogFile.log.

From the man page:

If --follow-name is specified, during an F command less will periodically attempt to reopen the file by name.

F          Scroll forward, and keep trying to read when the end of file is reached.

So if I understand correctly, less should keep trying to read MyLogFile.log. However, when my program restarts and rewrites MyLogFile.log, less does not see the new file until I restart less. But shouldn't less be "periodically attempting to reopen the file by name"? I must be missing something here. How can I use less as a log viewer when I'm constantly restarting my program?

For reference, here is the full explanation of --follow-name, which seems to totally contradict what I am experiencing:

Normally, if the input file is renamed while an F command is executing, less will continue to display the contents of the original file despite its name change. If --follow-name is specified, during an F command less will periodically attempt to reopen the file by name. If the reopen succeeds and the file is a different file from the original (which means that a new file has been created with the same name as the origi- nal (now renamed) file), less will display the contents of that new file.

I am using less version 458 and OSX 10.12.4.

4

1 回答 1

0

该文件需要在写入之前将其删除,以免引起注意。

我通过对两个终端窗口进行小实验发现了这一点:

在第一次我跑了less --follow-name file.txt(file.txt 已经存在),而在第二次我跑了echo text > file.txt. 少没注意到。我又试了一次,但这次我rm file.txt之前跑过echo,它奏效了。

谢谢橡皮鸭。

于 2017-05-09T22:54:46.270 回答