Skip to content
Advertisement

Filter followed tail to file using grep and redirect

I want to get the output of

tail -f /var/log/apache2/error.log | grep "trace1"

into a file. But

tail -f /var/log/apache2/error.log | grep "trace1" > output.txt

does not work, while the first command gives an output in my terminal window as expected.

I guess it has to do with the follow-parameter, because if I omit the “-f”, the output file is created.

But why is this so and how can I achieve my goal?

Regards, Axel

Advertisement

Answer

Can you please try:

tail -f /var/log/apache2/error.log | grep "trace1" | tee -a output.txt
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement