4 ms·
Think of it as saying "take fd 2 (stderr) and send it to the same place fd 1 is going now" So: $ command >file.txt 2>&1 first redirects fd=1 to file.txt an
by bodyfour 14y ago
Think of it as saying "take fd 2 (stderr) and send it to the same place fd 1 is going now" So:
$ command >file.txt 2>&1
first redirects fd=1 to file.txt and then has fd=2 go the same place. Where:
$ command 2>&1 >file.txt
first has fd=2 go the original place stdout was and then redirect fd=1 only to file.txt. Usually not what you want. If you really wanted file.txt to get only the stdout while simultaneously sending what used to be stderr to stdout I think you'd have to use another file descriptor like:
$ command 3>&1 >file.txt 2>&3
That is, save the original stdout as fd=3, redirect stdout, then make stderr go the same place fd=3 is going.