LINUX / A CONCEPT NOTE

Pipes & Redirection

how commands chain

~65 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

Linux processes communicate by default via three standard files: stdin (0), stdout (1), and stderr (2). Pipes (|) redirect the stdout of one command to the stdin of the next.

02 / FOLLOW THE MECHANISM

How redirection flows

  1. Process A

    runs and outputs text to its standard output (stdout).

  2. Pipe (|)

    kernel catches this stream and feeds it directly into Process B's standard input (stdin).

  3. Process B

    processes the input and writes its results to stdout.

  4. File redirect (>)

    writes the final output to a file on disk, overriding its contents.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

grep for error messages in a log file

cat logs.txt | grep -i error

EXAMPLE 02 · REFERENCE

append text to a file without deleting existing contents

echo \"new log\" >> output.log

Explore command anatomy in the CLI lab