Alex
Alex

Reputation: 44325

How to combine 'tail -f' and 'grep' in bash?

When I do

tail -f file.log

in bash every change of the file is shown on screen. But instead of listing every line of the file I only want to show lines containing a special string like special string. So I tried

grep 'special string' file.log | tail -f 

but this command returns to the bash immediately, not showing any future changes in the file.

How to do it correctly?

Upvotes: 3

Views: 5226

Answers (1)

tink
tink

Reputation: 15214

tail -f file.log | grep 'special string' 

Easy, huh :)

The problem with your order is that grep doesn't have tails ability to "follow".

Upvotes: 11

Related Questions