tail -f bar/somefile.log当 somefile.log 不存在时会立即失败。如何让 tail 无限期地等待创建该文件(稍后会发生)?
更新:使用-F,我看到:
tail: cannot open `bar/somefile.log' for reading: No such file or directory
tail: cannot watch parent directory of `bar/somefile.log': No such file or directory
Run Code Online (Sandbox Code Playgroud)
因为bar尚不存在(稍后将创建)。当bar创建somefile.log并被触摸时,tail 根本没有接受更改。
小智 39
你没有提到你需要它用于哪个操作系统,但tail在 linux 上有 --retry 和 --follow 选项可以做到这一点;
tail --retry --follow=name somefile.log
Run Code Online (Sandbox Code Playgroud)
cYr*_*rus 30
这有效:
while ! tail -f bar/somefile.log ; do sleep 1 ; done
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13587 次 |
| 最近记录: |