26

I was recently looking into using tail -f to monitor some text files like so: tail -f /var/sometext.

However, when I did some testing, it doesn't seem to work. What I did was I created a new file and ran: tail -f /home/name/text Then, I opened the log in vim and did some editing, saved it, and it seems that tail is not "seeing" the change.

The weird thing is, running echo "hello" >> /home/name/text seems to work fine (tail sees the change). I read somewhere this has something to do with file descriptors and new inodes being created when saving a file.

Can someone explain this for me? I didn't quite get how this actually works, but I have an idea what file descriptors are though.

1

3 Answers 3

41

-f follows by inode. If you want to follow by name, such as when a program completely recreates the file, then use -F instead.

2
  • 1
    Neat, I never knew that. It pays to read the manpages of utilities even(especially?) if you use them all the time!
    – Lyle
    Jan 5, 2019 at 22:12
  • --follow=name instead of -F is working too. Jan 22, 2023 at 23:24
1

tail -f watches the end of file, and when the end of file moves, it prints the new content and waits for the end of file to move again. In other words, changes in the middle of the document won't be found by tail -f, only appending.

-2

Actually, the true story is:

tail -f monitors memory, not disk. But it can't access protected memory, such as edits to a file opened a text editor.

1
  • The tail -f command operates on a file (file descriptor after opening the file). Although in fact the fresh modifications of the file are still in the memory (buffers, cache) it does not matter. tail still accesses the file through the file descriptor. It does not matter how the file is modified. --- The answer by Ignacio Vazquez-Abrams is correct - the editor does not modify the current file (which is opened in tail), it saves the changes to a new file with the same name as the old one. Feb 11, 2019 at 9:08

You must log in to answer this question.