Member-only story
2>&1
Introduction
If you’ve spent any time working in a Linux or Unix terminal, you’ve likely encountered the cryptic-looking snippet 2>&1 tucked into the end of a shell command, such as:
command > output.log 2>&1At first glance, this looks like line noise — a jumble of numbers and symbols. But 2>&1 is one of the most useful and frequently used pieces of syntax in Bash scripting. It controls how a program's output streams are captured and redirected. This post breaks down exactly what it means, why it works the way it does, and how to use it effectively in real-world scripts.
Non Member? Click Here
Background: The Three Standard Streams
Every process running in a Unix-like operating system is automatically given three communication channels, known as file descriptors:
By default, both stdout (normal program output) and stderr (error messages) are printed to your terminal screen. This is why, when you run a command that fails, you still see the error message even though you never explicitly asked for it — it's being written to stderr, which is displayed alongside stdout.
Bash allows you to redirect these streams — that is, send them somewhere other than their default destination (like a file, another stream, or /dev/null).







