Bash examples: redirecting output, error, input, etc

Last updated:
Table of Contents

Redirect stdout

To redirect the standard output (STDOUT) of a command to a file, use >:

$ command > out.txt

Redirect stderr

To redirect the standard error (STDERR) of a command to a file, use 2>:

$ command 2> err.txt

Redirect stdout and stderr

To redirect both STDOUT and STDERR to the same file, use &>:

$ command &> out_err.txt

Redirect stdout and stderr to different files

To redirect STDOUT to one file and STDERR to another file, just use > ad 2> at the same time:

$ command > out.txt 2> err.txt

Dialogue & Discussion