June 15, 2026 · by Meegrow Labs

How to Find Errors in Log Files (Terminal Detective)

An app on your screen is misbehaving. You don’t know why yet, but it does. The good news? The app already wrote down what went wrong, in a plain text file called a log. Your job is to read that file and catch the problem.

This is where you stop learning commands one by one and start using them together, like a detective lining up clues. And here’s the best part: you already know every tool you need.

To find errors in log files, run cat log.txt | grep error | wc -l: cat reads the file, grep error keeps only the lines that mention an error, and wc -l counts them. In one line, you know exactly how many faults the app logged.

What is a log file, and why does it hold the clues?

A log file is a running diary that a program writes for itself. Every time something happens, good or bad, the program jots a line into a file (often ending in .log or .txt). When the app breaks, the reason is usually sitting right there in those lines.

Think of it like the WhatsApp chat history of your app talking to itself. You don’t have to guess what happened, you just scroll back and read. The trouble is that a real log can have thousands of lines, and only a few of them matter. That’s the noise you need to cut through.

Which four commands help you find errors in log files?

You learned these one at a time in this level. Now they become your detective kit:

  • cat — reads a file and prints everything inside it.
  • grep — filters lines, keeping only the ones that match a word like error.
  • the pipe | — sends the output of one command straight into the next.
  • wc -l — counts lines, so you get a number instead of a wall of text.

Four small commands. Used alone they’re handy. Chained together, they solve a real problem. If you want a refresher first, revisit chaining commands with pipes and counting lines with wc before you try the challenge below.

How do I crack the case step by step?

The detective’s move is simple: read it, filter it, count it. Let’s build the command one piece at a time so you can see what each part does.

First, read the whole log:

cat log.txt

That prints every line, including all the boring ones. Now add the pipe and grep to pull out only the faults:

cat log.txt | grep error

You’ll see just the lines that contain the word error. The noise is gone. Finally, swap the screen-full of lines for a single count:

cat log.txt | grep error | wc -l

If the answer comes back as 3, you’ve found three errors, and there’s your culprit. The bug can’t hide anymore.

Why does this matter for real work?

This is not a toy exercise. Real developers do exactly this, dozens of times a day, to chase down bugs in apps, websites, and servers. When something crashes in production, the first instinct is to open the log and grep for the error.

Once you’re comfortable here, the same skill scales up. Later, when you start working with AI tools like Claude Code, you’ll often hand it a log and ask it to explain the errors you just found. Knowing how to surface those errors yourself makes you a far sharper partner for the AI. You can build this habit step by step in the free Zero to AI Hero course.

Try it right now

Open your terminal, make sure you have a file called log.txt nearby (or use any text file with the word error in it), and type:

cat log.txt | grep error | wc -l

Read the number it gives you. That’s how many errors the app logged. You just did real debugging with four commands you already knew.

Key takeaways

  • A log file is a program’s diary; when an app breaks, the reason is usually written inside it.
  • To find errors in log files, chain cat log.txt | grep error | wc -l.
  • cat reads, grep error filters out the noise, the pipe | connects them, and wc -l counts the matches.
  • The mindset is read, filter, count — the same move real developers use to debug every day.
  • Next up is the Level 3 review, where you’ll lock in everything you’ve learned about reading and searching files.

🚀 Take the full free course: Zero to AI Hero — learn to build with AI from scratch. New lessons daily, in Hindi & English.

Meegrow Labs

We help India go from zero to AI hero — learn to use & build with AI from scratch, in Hindi & English. Start the free course →

Want to actually learn this?

151 free 2-minute lessons — from "what's a file?" to building with AI.

▶ Start the free course