What are the three standard file descriptors in Linux and what are their numbers?
stdin = 0, stdout = 1, stderr = 2 — the three numbered streams every process gets for free.
* Every process starts with three wired-up descriptors: 0 (stdin), 1 (stdout), 2 (stderr). — Danielpr85, Public domain, via Wikimedia Commons. *
A file descriptor (FD) is just a small integer the kernel uses as a handle to an open stream. Every process is born with three of them already wired up:
| FD | Name | Default | Purpose |
|---|---|---|---|
| 0 | stdin | keyboard | where the program reads input |
| 1 | stdout | terminal | normal results |
| 2 | stderr | terminal | error and diagnostic messages |
Why two output streams instead of one? Splitting normal output (stdout) from errors (stderr) lets you treat them differently: pipe the real results onward while letting errors still reach your screen, or capture errors to a logfile and discard the rest. If everything shared one stream you couldn't separate "the answer" from "something went wrong."
The descriptor numbers are what you put in redirection operators — 2> means "FD 2", i.e. stderr. Programs can also open extra files, which get the next free numbers (3, 4, 5...).
Mnemonic: "0-1-2 = In-Out-Error."
Go deeper:
Standard streams — Wikipedia — stdin=0, stdout=1, stderr=2 and the file-descriptor concept.