Pipes and Redirection in Linux Explained (| > >> <)

Pipes and redirection connect commands and files together, letting the output of one command become the input of another.

Published October 2, 2026

A pipe (|) sends one command's output to another's input, while redirection (>, >>, <, 2>) sends streams to or from files. Together they let you chain small tools into powerful workflows.

How it works

> overwrites a file, >> appends, < feeds a file as input, 2> redirects errors, 2>&1 merges errors into output, and | connects commands.

Each tool does one job; pipes combine them.

Try it

cat access.log | grep 500 | wc -l
42
ls missing 2> errors.txt

Practical examples

Filter and count

grep ' 500 ' access.log | wc -l

Save output and errors

./build.sh > build.log 2>&1

Append

echo "done" >> log.txt

Tee to file and screen

make | tee build.log

Common mistakes

  • Using > and wiping a file by accident.
  • Order of 2>&1 (must follow the file redirect).
  • Expecting pipes to pass stderr (they pass stdout only).

Key takeaways

  • | chains commands.
  • > overwrite, >> append.
  • 2>&1 merges streams.

FAQ

What is /dev/null?

A black hole that discards output.

tee vs >?

tee writes to a file and passes output on.

More Linux articles