Redirect STDERR to STDOUT and then to file

Thu 10 April 2014 by Mikhail Basov

How to redirect STDERR to STDOUT and then redirect to file?

some_tool >file.txt 2>&1

Bash specific short form:

some_tool &>file.txt

Shell script to check pipe redirection:

1
2
3
#!/bin/sh
echo "sent to STDOUT"
echo "sent to STDERR" >&2

Comments