如何开始拖尾尚未创建的文件


12

tail用来监视我知道会将其进度写入磁盘的作业进度。几乎总是,我知道它们将在开始运行之前创建哪个文件(作业由超级计算机上的调度程序调度)

有没有一种方法,以tail这些文件被创建之前他们?我想这样做是在避免竞争条件和/或对作业如何或何时写入磁盘进行假设的同时。

Answers:


13

使用-F标志尾部(假设您tail来自GNU coreutils):

tail -F file-that-does-not-exist

来自man tail

   -F     same as --follow=name --retry
   --retry
          keep trying to open a file even when it is or becomes inaccessi
          ble; useful when following by name, i.e., with --follow=name
   -f, --follow[={name|descriptor}]
          output appended data as the file grows; -f, --follow, and --fol
          low=descriptor are equivalent

3

如果您的tail实现没有该--retry选项,则您可以自己作弊并创建文件:

$ touch file && tail-f file

根据您对所有权和权限的要求,可能就足够了。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.