EN
Bash - redirect command errors to file
0
points
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