How to Search Logs with Grep
Searching logs is one of the most common Linux troubleshooting tasks. Whether you are checking application errors, web server access logs or system logs, grep lets you quickly filter large files down to the lines that matter.
Basic search
grep "error" app.log
This prints every line in app.log that contains the word error.
Ignore case
grep -i "error" app.log
This matches error, Error and ERROR.
Show line numbers
grep -n "error" app.log
Line numbers are useful when you need to open the file and inspect the surrounding content.
Search recursively
grep -R "failed" /var/log
This searches through files below /var/log.
Search for multiple words
grep -E "error|warning|failed" app.log
The -E option enables extended regular expressions, which makes searching for multiple patterns easier.
Practice next
Try the Grep Command Quiz, read the Grep Cheat Sheet, or continue with the Advanced Grep Techniques guide.