In the shell, what does “ 2>&1 ” mean?
2016-03-18 11:27
483 查看
In a Unix shell, if I want to combine
So, if I want to use "head" on the output from g++, I can do something like this:
so I can see only the first few errors.
I always have trouble remembering this, and I constantly have to go look it up, and it is mainly because I don't fully understand the syntax of this particular trick. Can someone break this up and explain character by character what "2>&1" means?
Zero is
One is
Two is
File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).
Here is one way to remember this construct (although it is not entirely accurate): at first,
Symbole
转自: http://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean
stderrand
stdoutinto the
stdoutstream for further manipulation, I can append the following on the end of my command:
2>&1
So, if I want to use "head" on the output from g++, I can do something like this:
g++ lots_of_errors 2>&1 | head
so I can see only the first few errors.
I always have trouble remembering this, and I constantly have to go look it up, and it is mainly because I don't fully understand the syntax of this particular trick. Can someone break this up and explain character by character what "2>&1" means?
Zero is
stdin
One is
stdout
Two is
stderr
File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr).
Here is one way to remember this construct (although it is not entirely accurate): at first,
2>1may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named
1".
&indicates that what follows is a file descriptor and not a filename. So the construct becomes:
2>&1.
Symbole
>mean redirection.
>mean send to as a whole completed file, overwriting target if exist (see
noclobberbash feature at #3 later).
>>mean send in addition to would append to target if exist.
转自: http://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean
相关文章推荐
- 解决xshell 中文乱码
- Shell 符号 $0, $#, $*, $@, $?, $$
- 关于 shell到 linux服务器断掉进程的解决办法
- python subprocess模块的shell参数问题
- 修改sshd_config解决 xshell 链接 linux 错误 connection closed by foreign host
- Linux Shell命令(不定时更新)
- bash: ./build: /usr/bin/sh^M: 坏的解释器: 没有那个文件或目录
- xshell链接跳转
- Install ADDS on Windows Server 2012 R2 with PowerShell
- Linux Shell脚本编程--curl命令详解
- android自学问题一:dos命令行输入adb shell命令报错
- adb shell命令详解
- Shell编程-批量增删用户
- Linux系统运行状况相关的Shell命令
- shell的调试技术
- linux - 怎么自动填写有交互的shell脚本 - SegmentFault
- ZShell
- linux - 怎么自动填写有交互的shell脚本 - SegmentFault
- linux - 怎么自动填写有交互的shell脚本 - SegmentFault
- linux - 怎么自动填写有交互的shell脚本 - SegmentFault