Find files and search for within tail

findgreptail

The following is working as expected.

find /opt/ -name "somefile.out" -exec grep 'Connection refused' {} \; | more

But if I want to search only in the tail of the found files, I can not add tail or tail -100 like this…

find /opt/ -name "somefile.out" -exec grep 'Connection refused' tail {} \; | more

What is the best way to search for text in the last few lines?

Best Answer

This seems to work for me, not sure if it's the best way:

find . -name '*.log' -exec tail {} \; | grep GET | more

The main thing is executing the commands in a more correct order.

Good luck!