Python I/O Redirection: >, >>, 2>, 2>&1, &>, /dev/null & Here-Strings
Every process in Linux is assigned three default I/O file descriptors: Standard Input (`0: stdin`), Standard Output (`1: stdout`), and Standard Error (`2: stderr`). Redirection operators control where program output goes (files, null devices, or other streams).
"A command is a machine with 1 input funnel (0) and 2 output spouts: blue for normal products (1: stdout) and red for error alerts (2: stderr). Redirection hooks hoses onto those spouts to direct flows to specific buckets."
Deep Dive: How It Works
File Descriptors: `>` (redirect stdout / truncate), `>>` (redirect stdout / append), `2>` (redirect stderr), `2>&1` (merge stderr into stdout), `&>` (redirect both stdout and stderr).
The `/dev/null` Black Hole: Discard unwanted noisy output by redirecting to `/dev/null` (e.g. `cmd > /dev/null 2>&1`).
Here-Strings (`<<<`): Pass a string variable directly to standard input: `grep "pattern" <<< "$MY_VAR"`.
Syntax Blueprint
command > output.log 2> error.log # Separate logs command >> app.log 2>&1 # Combined append command > /dev/null 2>&1 # Completely silent base64 -d <<< "WmVubGFi" # Here-string input
Use 2>&1 to merge error streams and /dev/null to silence command output.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Thinking `2>&1` and `&>` behave identically in legacy `/bin/sh` POSIX scripts.Why it happens: `&>` is a Bash extension; standard POSIX `sh` requires `> file 2>&1`.
How to fix: Use `> file 2>&1` for universal cross-shell compatibility.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Feed Input with a Here-String
Use `tr 'a-z' 'A-Z' <<< "zencompiler"` to convert a here-string.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.