Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Hi I wanna keep looking at a log file, but I also don't wanna see irrelevant stuff, I'm only interested in anything with "foobar" in it.

So if I was tailing the file I would do

 tail file | grep "foobar"

Now that I'm adding the -f option, is there a way to somehow only show the stuff that I want? using grep or other technique?

share|improve this question
It appears your answer is already written here:… – uSlackr Jan 9 '12 at 16:58
It appears that xyr answer is in the question. – JdeBP Jan 9 '12 at 17:02
up vote 31 down vote accepted

You almost wrote the answer, which is :

tail -f file.log | grep "foobar"

That's it.

share|improve this answer
Woah, you are right, I think I didn't expect this to work, I still don't, isn't piping supposed to happen when a command has finished execution? I guess this shows that it's not, it happens every time there an output, right? – user893730 Jan 9 '12 at 21:15
No it will launch the two programs in parallel, and the second one (grep) will exit as soon as tail's STDOUT closes. That's the whole point of pipes, data streaming :) – Ravachol Jan 10 '12 at 9:57
When grep is the last line in the pipe, its output is line buffered, so you see the filtered output of tail -f live, rather than delayed. Note that if you were to use multiple grep commands, any whose output was piped would need a --line-buffered option (assuming GNU or BSD grep) in order to keep this behaviour. – ghoti Jul 4 '13 at 6:44

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.