Skip to content
zero2vibecodelearn vibe coding
Level 3 · Search and pipes 6 min Reviewed by the author · Aug 4, 2026

The pipe: joining commands together

The `|` symbol feeds one command's output straight into the next one, so small tools combine into exactly the tool you needed.

Level 3 · 0 / 4 lessons0%

Every command so far has printed to the screen. The sends that output somewhere better: into another command.

The vertical bar

cat server.log | grep ERROR
ERROR database timeout
ERROR disk full

Read it left to right:

  1. cat server.log produces the file’s text
  2. | catches that text instead of letting it hit the screen
  3. grep ERROR receives it and filters it
  4. What survives gets printed

Notice that grep has no file name after it. It does not need one — it is reading from the pipe.

Note

Most of these tools follow the same convention: given a file name, read the file; given none, read whatever comes in through the pipe. That one rule is what makes them all connectable.

Quick check

Why does grep take no file name in `cat notes.txt | grep TODO`?

Chains

Pipes stack. Each stage takes what the last one produced:

grep INFO server.log | wc -l

grep pulls out the routine lines, wc -l counts them, and you get a single number back. Three lines of thinking, one line of typing.

You can keep going:

cat server.log | grep -v INFO | wc -l

Take the log, drop the routine lines, count what is left. Nothing here is a special “log analysis” tool — it is three general commands wired together.

Quick check

What does `cat data.txt | grep error | wc -l` produce?

Building a chain without guessing

Do not write a four-stage pipe and hope. Build it one stage at a time and look at the output after each:

cat server.log
cat server.log | grep -v INFO
cat server.log | grep -v INFO | wc -l

Each step is checkable. When the answer at the end looks wrong, you already know which stage to suspect.

Tip

This is exactly how to read a long pipeline an AI agent hands you: cover everything after the first | and ask what the first part produces. Then uncover one stage at a time. A ten-stage pipeline is never complicated at any single point.

Quick check

An agent gives you a pipeline with four stages and you are not sure about it. What is the cheapest way to understand it?

Where it goes next

Combine what you already have and the pipe becomes genuinely powerful:

find . -name "*.log" | wc -l

That counts log files anywhere in the project — a question neither command could answer alone.

Try it

  1. cat server.log — the whole file, six lines.
  2. cat server.log | grep ERROR — the same data, filtered down to two.
  3. grep INFO server.log | wc -l — a count of the routine lines instead of the lines themselves.

Step 3 is worth a second look: the output changed shape entirely. Lines went in, a number came out. Each stage in a pipe is free to transform, not just filter.

Check your understanding

Answered 0/3
Mode:

What does `|` do?

In `cat log.txt | grep ERROR`, why does grep have no file name after it?

How many commands can you chain with pipes?

Finish the task in the terminal and answer the questions to complete the lesson.

📝 My notes

Saved automatically in this browser · shows up on the Notes page.

Task

Send the log through grep with a pipe, then count the routine lines.

Tab complete · history · Ctrl+L clear · help commands

  • Not done: Pipe cat into grep
  • Not done: The filtered lines come through the pipe
  • Not done: Pipe something into wc -l

Lesson Q&A

What does `|` do?

A pipe is a connector. The left command prints, the right command reads what it printed instead of a file.

In `cat log.txt | grep ERROR`, why does grep have no file name after it?

Most of these tools read a file if you name one, and read the pipe if you do not.

How many commands can you chain with pipes?

Each stage narrows or reshapes the text. Long chains are normal and are read left to right.

Why does grep take no file name in `cat notes.txt | grep TODO`?

A tool reads the pipe when you do not hand it a file. That is the whole convention behind pipes.

What does `cat data.txt | grep error | wc -l` produce?

Read left to right: whole file, then only matching lines, then a count of those lines.

An agent gives you a pipeline with four stages and you are not sure about it. What is the cheapest way to understand it?

Each stage is simple on its own. Stepping through them turns one confusing line into four obvious ones.

Move between lessons with · search with ⌘K