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

I'm using the following command

tail -f /mydir/myfile |  grep "searchterm" >> outfile

Without the -f it works fine, but with the -f, which I need, nothing is written to the file. The following outputs to the console just fine

tail -f /mydir/myfile |  grep "searchterm"

What do I need to do in order to get my command to correctly write out to a file?

share|improve this question
up vote 6 down vote accepted

If you have GNU grep:

tail -f /mydir/myfile |  grep --line-buffered "searchterm" >> outfile

Which will write every line, for a performance penalty.

Alternatively, wait for more output. If you're killing the processes, just kill the tail process and the buffer should flush before grep exits.

share|improve this answer
I will try this out first thing Monday and report back. Thanks for the quick reply. – pyInTheSky Feb 23 '13 at 17:57

Is grep buffering the output perhaps, making it appear like there is none? Try:

tail -f /mydir/myfile | grep --line-buffered "searchterm" >> outfile
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.