相當於 OS X 下的 tail/less --follow-name

相當於 OS X 下的 tail/less --follow-name

我需要尾部-f輪換的日誌檔案。

這是精確的與此處的問題相同,但在 OS X 上:

為什麼少尾模式停止運作?

那麼如何在 OS X 下持續追蹤 inode 可能發生變化的檔案呢?

答案1

來自 Ubuntu Lucid (coreutils 7.4)

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

   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

從 Mac OS X 10.6 (10A432)

 -f      The -f option causes tail to not stop when end of file is
         reached, but rather to wait for additional data to be appended to
         the input.  The -f option is ignored if the standard input is a
         pipe, but not if it is a FIFO.

 -F      The -F option implies the -f option, but tail will also check to
         see if the file being followed has been renamed or rotated.  The
         file is closed and reopened when tail detects that the filename
         being read from has a new inode number.  The -F option is ignored
         if reading from standard input rather than a file.

假設您想要 --follow=/tmp/某事.txtLinux 上的行為,這意味著在 Mac 上你想要的是:

tail -F /tmp/somefile.txt

編輯:剛剛在 Mac OSX (Snow Leopard) 上測試過-F只會開啟您輸入的檔案名,並且不會跟隨移動時開啟的檔案的索引節點/檔案描述符。

相關內容