Bash 5 reference · Shell Builtins and Syntax

redirection (Bash syntax)

Send output to files, read input from files, merge stderr into stdout, and discard output with /dev/null.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

cmd > file   cmd >> file   cmd 2> file   cmd &> file   cmd 2>&1   cmd < file

Parameters

ParameterDescription
> Overwrite a file with stdout.
>> Append stdout.
2>&1 Send stderr where stdout goes.
&> Both stdout and stderr to a file.
<( cmd ) Process substitution: a command's output as a file.

Examples

Overwrite, append, stderr
echo one > out.txt; echo two >> out.txt
ls nope 2> err.txt || true
wc -l < out.txt; grep -c 'nope' err.txt

Output

2
1

Run this on your computer — see “Get Started” for setup.

Process substitution
diff <(printf 'a\nb\n') <(printf 'a\nc\n') || true

Output

2c2
< b
---
> c

Run this on your computer — see “Get Started” for setup.

Was this page helpful?