1

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.

Kevdog777
  • 3,224
jaybee
  • 11
  • 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

2 Answers2

0

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.

MelBurslan
  • 6,966
igiannak
  • 750
0
pgrep -f 'tail -f your_filename'|xargs kill