AI Hints
Linux · Lesson 45 of 120

Practice: Log Detective

Grep in action.

⏱ 2 min read▶ Video at 57:30🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Something went wrong on the website this morning. Customers say the shop page broke. Let's use grep to investigate the log, like a detective.

Practice: Log Detective
From the video: Practice: Log Detective
  • The shop page broke
  • Investigate the log
  • grep is our magnifying glass

Your questions

Here are three questions. How many errors were there in total? Which errors involved the shop page? And did the user jo have any problems at all? Pause, and try answering them with grep.

Q1how many errors?
Q2errors on /shop?
Q3any problems for jo?
Toolgrep and its options

The answers

Grep dash C ERROR counts seven errors. Grep failed slash shop shows the shop errors, with their times. And for jo, we search for jo, and then hide the INFO lines, using a pipe into grep dash V. Jo had two slow pages, and one error, on the shop page.

Terminal
grep -c ERROR logs/server.log
7
grep "failed /shop" logs/server.log
2026-01-05 09:07:00 ERROR jo failed /shop
2026-01-05 09:17:21 ERROR alex failed /shop
grep jo logs/server.log | grep -v INFO
2026-01-05 09:03:58 WARN jo slow page /cart
2026-01-05 09:07:00 ERROR jo failed /shop
2026-01-05 09:26:18 WARN jo slow page /home

Thinking like a detective

Notice how we narrowed things down, one step at a time. Start broad, like all errors. Then add a detail, like the page. Then combine searches with a pipe. That's how people really investigate problems on servers.

keyvalue
Start broadgrep ERROR
Add detailgrep "failed /shop"
Combinegrep jo | grep -v INFO
Countgrep -c

Summary

You investigated a real log, by counting, narrowing down, and combining searches. Next, the pipe itself, the most powerful idea in the shell.

Key takeaways
  • Count with -c
  • Narrow down
  • Combine with |
Next up: Pipes — joining commands together