June 15, 2026 · by Meegrow Labs

Chaining Commands With Pipes in the Terminal

You already know how to read a file with cat and how to search inside it with grep. But what if you could make one feed straight into the other, without saving anything in between? That little trick is the heart of every powerful terminal workflow.

Chaining commands with pipes means using the | symbol to take the output of one command and hand it directly to the next, so you can stack simple tools into one smart action.

What is the pipe symbol?

The pipe is the straight up-and-down line: |. On most keyboards it sits just above the Enter key, and you type it with Shift. It is not a capital I or a lowercase l, even though they look similar.

When you put a pipe between two commands, you are telling the terminal: “run the first one, then feed whatever it prints into the second one.” Nothing gets saved to a file along the way. The data just flows.

How does chaining commands with pipes work?

Think of an assembly line. The first command runs and produces some output. The pipe grabs that output and passes it along. The next command takes it as its input and refines it further.

The rule is simple: output becomes the next input, every time. You can keep adding more pipes to add more steps, each one doing one small job.

  • The first command makes the data.
  • The pipe carries it across.
  • The next command shapes or filters it.

Can I see a real example?

Say you have a log file full of hundreds of lines, and you only care about the lines that mention an error. You could read the whole file with cat and scroll forever, or you could pipe it into grep and let the terminal do the work:

cat log.txt | grep error

Here is what each piece does:

  • cat log.txt reads the file and prints every line.
  • | passes those lines along to the next command.
  • grep error keeps only the lines that contain the word “error”.

Two tools you already learned, working together. cat is how you read it, the pipe is how you pass it, and grep is how you filter it. Only the error lines come back.

Why does this matter?

This is one of the biggest ideas in using a computer like a builder. Instead of hunting for one giant tool that does everything, you combine small, sharp tools that each do one thing well.

One command makes the data. The next refines it. The one after that counts it or sorts it. By stacking simple tools with pipes, you can answer real questions about real files in a single line, the same way professional developers do every day.

How do I try it right now?

Open your terminal, move into a folder that has a text file, and type this (swap in any file that has the word you want to find):

cat log.txt | grep error

If you do not have a log file handy, try it on any file you do have, searching for any word. Watch how only the matching lines come back instead of the whole file. That is chaining commands with pipes in action.

This builds directly on the searching you did with grep in the previous lesson, and it sets you up for the next one, where you will pipe output into wc to count lines and words. You can follow the whole sequence in the free Zero to AI Hero course, which takes you from “what’s a file?” to building real things with AI, step by step.

Key takeaways

  • The pipe symbol | connects two commands so the first one’s output feeds the second.
  • Chaining commands with pipes works like an assembly line: output becomes the next input.
  • cat log.txt | grep error reads a file and shows only the lines containing “error”.
  • You can stack many pipes to combine simple tools into one powerful command.
  • Next up: counting lines and words with wc.

🚀 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