← Cheat Sheets
Shell Redirection and Pipes
Control where input and output go.
# Shell Redirection and Pipes
Control where input and output go.
| Syntax | Meaning |
|---|---|
| `cmd > file` | Write output to file (overwrite) |
| `cmd >> file` | Append output |
| `cmd < file` | Read input from file |
| `cmd 2> err.txt` | Redirect errors |
| `cmd > out.txt 2>&1` | Output and errors to one file |
| `cmd1 \| cmd2` | Pipe output of cmd1 into cmd2 |
| `cmd > /dev/null` | Discard output |
| `cmd \| tee file` | Show and save output |
| `$(cmd)` | Use a command's output inline |
| `a && b` | Run b only if a succeeds |
| `a \|\| b` | Run b only if a fails |
| `a; b` | Run both in sequence |