Bash Operators Table

–click an operator to copy it
OperatorNameWhat it does
|PipeSends stdout of the left command to stdin of the right command
>Redirect outWrites stdout to a file, overwriting it
>>Redirect appendAppends stdout to a file
2>Redirect stderrWrites stderr to a file
2>&1Redirect stderr to stdoutMerges stderr into stdout stream
<Redirect inReads stdin from a file
&&Logical ANDRuns the right command only if the left succeeded (exit 0)
||Logical ORRuns the right command only if the left failed (non-zero)
;SemicolonRuns commands sequentially regardless of exit status
&BackgroundRuns the command in the background
$(...)Command substitutionReplaces with the stdout of the inner command
`...`Backtick substitutionLegacy command substitution - use $(...) instead
$VARVariable expansionReplaces with the value of the environment or shell variable
${VAR:-default}Default valueUses default if VAR is unset or empty
<<<Here-stringSends a string as stdin to a command
Operators follow the GNU Bash Reference Manual (1 MB single-page HTML, the definitive reference). The three that trip up everyone: 2>&1 looks like “redirect 2 into 1” but actually means “send file descriptor 2 to wherever file descriptor 1 currently points” - so 2>&1 after >file works but before it doesn’t; || and && are short-circuit operators borrowed from C; and $(...) is preferred over backticks because backticks cannot nest. Bottom line: the pipe | is the single most important operator in Unix - it is why small composable tools beat monolithic programs, a design philosophy from 1973 that still defines the terminal. Terminal tools: HTTP methods table, chmod calculator, ASCII table, JSON escape tool.

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

  1. Filter by operator character, name, or category - pipe, redirect, logical, substitution.
  2. Click any operator to copy the character for use in a script or documentation.
  3. 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 &ldquo;make file descriptor 2 go wherever file descriptor 1 currently points.&rdquo; 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.

Related tools