简体   繁体   中英

tail -f logfile is not showing the newly added entries

I have a log file contents of log.file are

123
123
321
312
123
412
151

I have done tail -f log.file . In other session, I have opened the same log file and appended more values. my assumption is that tail -f log.file should show the newly appended values but its not showing.

That depends on how you open the file and append. You have to make sure the change happens "in place"

This will work:

echo >> logfile

This won't:

vi logfile

Why not? vi is equivalent to:

mv logfile logfile~
echo >> logfile

After this sequence of commands, tail -f will follow logfile~ ; it won't see the newly created file.

This happens because tail doesn't follow the name; it follows the file descriptor which doesn't change when the name changes. This approach allows Unix all kinds of neat tricks (like echo appending to the file while tail has it open).

tail -F would work since it notices that the file was renamed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM