I want to tail -f file but going tailing it after a mv.

The tail manpage tells me: -f means --follow=descriptor so a mv should not change the inode?

Why does tail -f stop working after the rename?

  • Are you moving across filesystems/partitions? – grawity Oct 12 '14 at 18:03
  • No, just in the same directory. Tested on Manjaro and Ubuntu 14.04 – Psi Oct 12 '14 at 18:04
  • use tail -F to follow modulo renames, as in superuser.com/a/1058674 – timotheecour Nov 16 '16 at 0:56

Reading tail sources, it appears that it does not fail at reading the renamed file, but it fails at monitoring the file status.

More precisely, tail appears to behave this (simplified) way:

  1. it reads the file to the end;
  2. then setup an inotify watch in order to be noticed when something happens to the file;
  3. when new content is appended to the file, read again to the end;
  4. then jump back to step 2.

When you move the file, inotify informs tail, which in turn decides to drop the file from the list of the monitored files. It appears to be intentional, although it is not clear to me why this is so (and I would expect it to keep monitoring the file after rename). The relevant lines appear to be these.

So, the problem is not with the underlying Linux operating system, but with the way tail handles file renaming.

  • 2
    I see youre completley right. For me its a bug in tail, either in the code or in the documentation. I use tail wihtin a NodeJS script in wrapped it around with my own inotify watcher to re-init tail using the renamed file, not a elegant way but it works. – Psi Oct 13 '14 at 10:48

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.