What's the difference of redirect an output using >
, &>
, >&
and 2&>
?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
>
redirects stdout to a file2>&
redirects file handle "2" (almost always stderr) to some other file handle (it's generally written as2>&1
, which redirects stderr to the same place as stdout).&>
and>&
redirect both stdout and stderr to a file. It's normally written as&>file
(or>&file
). It's functionally the same as>file 2>&1
.2>
redirects output to file handle 2 (usually stderr) to a file.
回答2:
1> (or >) is for stdout, the output of a command. 2> is for stderr, the error output of the command.
This page is a bit wordy, but has good explanations and examples of the different command combinations.