Handy Hints: tail | grep

When trying to track an issue in log files on a live system, I find it handy to tail the logs. If the logs are being populated to quickly too find what I am looking for, I would pipe tail to grep and match on a pattern.

tail -f query.log | grep "thing I'm interested in" --color

Now you will see any new lines added to query.log that contain “thing I’m interested in” highlighted. Any other lines will be ignored.

About Anthony Batchelor

Job: Software engineer at Mercurytide Hobbies: Guitar/Band, Kendo, Beer Brewing, Simple Electronics, Python hacking.
This entry was posted in How-to, sys-admin. Bookmark the permalink.

2 Responses to Handy Hints: tail | grep

  1. There are times where I’m not exactly sure which logfile will be getting the output, so I’ll give tail wildcards or multiple files, and it’ll glob it and watch all the files on the command line. It can be very handy.

    I’m getting ready to put out a large entry on logging on my blog, so if you’re interested in it, keep an eye out.

    Good hint, thanks!

    –Matt

  2. Thanks for the tip. I’ll keep an eye on your feed.

    Tony

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>