使尾巴等待文件存在


25

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

因为bar还不存在(稍后会创建)。当bar被创建somefile.log并被感动时,尾巴根本没有吸收变化。

Answers:




6

首先创建文件:

touch somefile ; tail -f somefile

精美优雅的逻辑解决方案。
CarComp
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.