Syntax

Bash Redirect Errors Syntax

In Bash, redirect errors: sends errors to a file, or errors and output together — command 2> err.txt command > all.txt 2>&1

Quick Answer

Syntax
command 2> err.txt command > all.txt 2>&1
BashSyntax

Redirect Errors

Code example
command 2> err.txt command > all.txt 2>&1

Sends errors to a file, or errors and output together.

Learn More

How to redirect errors in Bash

  1. Open your Bash file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Bash Redirect Errors Syntax

Use command 2> err.txt command > all.txt 2>&1.

Related Syntax References

Frequently asked questions

What is the Bash syntax for redirect errors?

Use this pattern: command 2> err.txt command > all.txt 2>&1

Can I copy this Bash code example?

Yes. Use Copy code and adapt the example to your program.

Is this Bash syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify