Sitemap
Nirbhay Singh

Nirbhay Singh

Technophile, Assistant Vice President at CITI, talks about AI, DevOps, Cloud, SRE, Linux and Programming. https://buymeacoffee.com/nirbhaysingh281

Member-only story

2>&1

4 min readSep 18, 2026

--

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>&1

At 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:

Press enter or click to view image in full size

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).

--

--

Nirbhay Singh
Nirbhay Singh

Written by Nirbhay Singh

Technophile, Assistant Vice President at CITI, talks about AI, DevOps, Cloud, SRE, Linux and Programming. https://buymeacoffee.com/nirbhaysingh281