I use tail to monitor the progress of jobs that I know will write their progress to disk. Almost always, I know which file they will create before they start running (the jobs are dispatched by a scheduler on a supercomputer)

Is there a way to tail these files before they are created? I would like to do so while avoiding race conditions and/or making assumptions about how or when the jobs write to disk.


Use the -F flag to tail (assuming you have tail from GNU coreutils):

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

From man tail:

   -F     same as --follow=name --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

If your tail implementation does not have the --retry option, you could probably just cheat and create the file yourself:

$ touch file && tail-f file

Depending on your requirements with respect to ownership and permissions that might be sufficient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.