Languages
[Edit]
EN

Bash - redirect command errors to file

0 points
Created by:
Dirask Admin - Marvin
1820

This article will show you how to redirect command errors to file in Bash.

Quick solution:

command 2> errors.txt

Note:

If you want data to be added to an existing file use >> instead of >.

 

Practical examples

In the example below, we will try to execute a wrong command that bash will not recognize - normally the result would be the message bash: sample_invalid_command: command not found.

Command:

$ abcd 2> errors.txt

After executing the above line, no message will be displayed, but the contents of the errors.txt file will looks like this:

bash: abcd: command not found

Bash

Bash - redirect command errors to file
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join