This question already has an answer here:

How can you stop a tail -f command after seeing a specific string/word?

I'm trying to follow an expanding log and stop the tail after finding a specific word. Is there any kill command for that? I'm just starting with UNIX.

marked as duplicate by MelBurslan, Jeff Schaller, jimmij, don_crissti, G-Man Jun 24 '16 at 23:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Surely, tail -f is a command that you ran from the command line? So then doing a Ctrl C – Kevdog777 Jun 24 '16 at 14:34
  • actually no, ill be using it inside a script. I wanted to follow a log that is expanding then i want to stop the tail command if it see a specific string. – jaybee Jun 24 '16 at 14:52
pgrep -f 'tail -f your_filename'|xargs kill

you can enable the grep line buffering if you want to tail file with ongoing writing:

tail -f your_file | grep --line-buffered your_pattern

else if the file is static you can grep your file the pattern you are looking for.

  • 1
    tail -f log.txt | grep --line-buffered "error" like this? – jaybee Jun 24 '16 at 14:22

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