In the shell, what does “ 2>&1 ” mean?
In a Unix shell, if I want to combine stderr
and stdout
into the stdout
stream 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>1
may 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 (seenoclobber
bash 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
最新文章
- UWP 禁止Pivot swip 手势
- macos开发pgsql数据库
- javafx之两种局部界面的呈现方式
- [wxWidgets] 1. 安装及";hello world";程序
- Xena测试仪的自动化
- 高性能Java网络框架 MINA
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
- JAVA! static什么作用?
- android照片墙的实现
- java中-静态代码块、构造代码块、构造方法的联系
- python网络编程(UDP+广播)
- 【NOIP数论内容整理】
- golang 中的指针
- Oracle 数据库 Only 导出空表的方法
- Win7 启动修复
- android: ADB错误“more than one device and emulator”
- 2019.02.06 bzoj2187: fraction(类欧几里得)
- kali删除软件
- 【PaddlePaddle系列】CIFAR-10图像分类
- TCP/IP协议、HTTP协议