Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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.

share|improve this answer
If you any source links, can you please post those links? I would like to do further reading on that. Thanks for reply. – user14039 Mar 14 '12 at 18:16
@tech_learner Look into race conditions. The article is more focused on single variables, but the same principles apply to whole files (even more so, perhaps). – Kevin Mar 14 '12 at 18:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.