Bash Operators Table
| Operator | Name | What it does |
|---|---|---|
| | | Pipe | Sends stdout of the left command to stdin of the right command |
| > | Redirect out | Writes stdout to a file, overwriting it |
| >> | Redirect append | Appends stdout to a file |
| 2> | Redirect stderr | Writes stderr to a file |
| 2>&1 | Redirect stderr to stdout | Merges stderr into stdout stream |
| < | Redirect in | Reads stdin from a file |
| && | Logical AND | Runs the right command only if the left succeeded (exit 0) |
| || | Logical OR | Runs the right command only if the left failed (non-zero) |
| ; | Semicolon | Runs commands sequentially regardless of exit status |
| & | Background | Runs the command in the background |
| $(...) | Command substitution | Replaces with the stdout of the inner command |
| `...` | Backtick substitution | Legacy command substitution - use $(...) instead |
| $VAR | Variable expansion | Replaces with the value of the environment or shell variable |
| ${VAR:-default} | Default value | Uses default if VAR is unset or empty |
| <<< | Here-string | Sends a string as stdin to a command |
Bash operators are the grammar of the terminal - the pipe | connects programs, redirects > and >> capture output, && and || control flow, and $(...) nests commands. This table covers all 15 essential operators from the GNU Bash Reference Manual, the 1 MB single-page document that is the definitive source.
The three that separate beginners from intermediate users: 2>&1 (redirect stderr to stdout - the direction matters), || (run the fallback only on failure - the shell’s if-else), and $(...) (nest any command inside any other - the composable building block of Unix).
How to use
- Filter by operator character, name, or category - pipe, redirect, logical, substitution.
- Click any operator to copy the character for use in a script or documentation.
- Read the third column for the one-sentence explanation - each entry is a rule, not a paragraph.
Frequently asked questions
Why does 2>&1 have to come after > file?
2>&1 means “make file descriptor 2 go wherever file descriptor 1 currently points.” If you write 2>&1 > file, fd 1 still points to the terminal when the redirection happens, so stderr goes to the terminal and stdout goes to the file. The correct order is > file 2>&1, or the modern shortcut: &> file.
What is the difference between $() and backticks?
Both do command substitution, but $() can nest: echo $(echo $(echo inner)). Backticks cannot nest without escaping - the inner backtick terminates the outer one. $() was introduced in ksh93 and adopted by POSIX as the standard; backticks exist for backward compatibility only.
What is the difference between && and ;?
&& is a short-circuit: the second command runs only if the first succeeded (exit code 0). Semicolon runs both regardless. cd /nonexistent && rm -rf / is safe because cd fails; cd /nonexistent; rm -rf / is catastrophic because rm runs anyway. This distinction is why && is the operator in CI/CD pipelines.
What does the & at the end of a command do?
It runs the command in the background - the shell prompt returns immediately while the command continues. The process gets a job number and you can bring it back with fg or check it with jobs. Output still goes to the terminal unless you redirect it.