Free — no signup required

Redirection Basics: >, >>, and 2>

1 min read

Managing Streams

Every process in Linux is born with three open file descriptors — numbered channels through which data flows:

Number Name Default Destination
0 STDIN (Standard Input) Keyboard
1 STDOUT (Standard Output) Terminal screen
2 STDERR (Standard Error) Terminal screen

By default, STDOUT and STDERR both print to your terminal, mixed together. Redirection lets you point these streams at files instead.

Overwriting output (>): takes STDOUT and saves it to a file, creating the file if it does not exist, or overwriting it completely if it does.

Appending output (>>): takes STDOUT and adds it to the end of a file, preserving existing content — the difference between destroying a log's history on every run and accumulating it.

Redirecting errors (2>): the 2 is the file descriptor number for STDERR. Redirecting it captures only error messages to a file, leaving normal output on the screen (or wherever STDOUT is separately redirected to).

This separation is powerful in automation: you can log errors to one file and normal output to another, making post-run diagnosis much easier.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free