Why does tailing an output log sometimes give partial lines

pipetail

Sometimes, tailing an output log which is constantly being updated doesn't give the whole lines. Why is that?

grep pattern input_file > output.log &
tail output.log

Why doesn't it print the last line in full?

Best Answer

Reading and writing a file is not line-atomic, and tail -f is not line-buffered. So, when tail -f reads the file while it was still being written, it may reach the end of the file (and therefore stop printing) before the process writing to the file writes the end of the line. When that happens, it prints an incomplete line because that's all it sees.

Related Question