Lesson 22 / 31
Redirection
Redirect stdout, stderr and stdin with >, >>, 2> and /dev/null to save or silence output.
By Rahul Agarwal · 15 years in web development · Updated 1 Oct 2026
Two output streams
Every process has stdout (normal output) and stderr (error output), plus stdin for input. Redirection lets you send these to files instead of the screen.
>, >> and 2>
> overwrites a file with stdout, >> appends, 2> captures stderr separately.
ls /etc > listing.txt # overwrite
ls /etc >> listing.txt # append
ls /nope 2> errors.txt # stderr only
Output:
cat errors.txt # ls: cannot access '/nope': No such file or directory
Discard output
/dev/null is a black hole — redirect unwanted output there: command > /dev/null 2>&1 silences everything.