I'm trying to watch for any new output of a log file. Another script (not under my control) is deleting the file then creating a new one with the same name. Using tail -f
doesn't work because the file is being deleted.
Tail -f File Deleted and Re-Created – How to Handle
tail
Best Answer
If your
tail
supports it, usetail -F
, it works nicely with disappearing and re-appearing files. Just make sure you starttail
from a directory which will stay in place.-F
is short-hand for--follow=name --retry
:tail
will follow files by name rather than file descriptor, and will retry when files are inaccessible (e.g. because they’ve been deleted).(A number of bugs relating to
--follow=name
with--retry
were fixed in coreutils 8.26, so you may run into issues with earlier versions; e.g. retrying when the directory containing the tailed file is deleted appears to only work in all cases with version 8.26 or later.)