/dev/null 2>&1 什么意思
2013-07-26 15:55
531 查看
在Unix中,标准输入设备 stdin是0, stdout 是1, stderr是 2。
/dev/null 2>&1这样的写法意思是将标准输出和错误输出全部重定向到/dev/null中,也就是将产生的所有信息丢弃.
下面说说 command > file 2>file 与command > file 2>&1 有什么不同的地方.
首先~command > file 2>file 的意思是将命令所产生的标准输出信息,和错误的输出信息送到file 中.command > file 2>file 这样的写法,stdout和stderr都直接送到file中, file会被打开两次,这样stdout和stderr会互相覆盖,这样写相当使用了FD1和FD2两个同时去抢占file 的管道.
而command >file 2>&1 这条命令就将stdout直接送向file, stderr 继承了FD1管道后,再被送往file,此时,file 只被打开了一次,也只使用了一个管道FD1,它包括了stdout和stderr的内容.
从IO效率上,前一条命令的效率要比后面一条的命令效率要低,所以在编写shell脚本的时候,较多的时候我们会用command > file 2>&1 这样的写法.
/dev/null 2>&1这样的写法意思是将标准输出和错误输出全部重定向到/dev/null中,也就是将产生的所有信息丢弃.
下面说说 command > file 2>file 与command > file 2>&1 有什么不同的地方.
首先~command > file 2>file 的意思是将命令所产生的标准输出信息,和错误的输出信息送到file 中.command > file 2>file 这样的写法,stdout和stderr都直接送到file中, file会被打开两次,这样stdout和stderr会互相覆盖,这样写相当使用了FD1和FD2两个同时去抢占file 的管道.
而command >file 2>&1 这条命令就将stdout直接送向file, stderr 继承了FD1管道后,再被送往file,此时,file 只被打开了一次,也只使用了一个管道FD1,它包括了stdout和stderr的内容.
从IO效率上,前一条命令的效率要比后面一条的命令效率要低,所以在编写shell脚本的时候,较多的时候我们会用command > file 2>&1 这样的写法.
相关文章推荐
- >/dev/null 2>&1 是什么意思[转]
- shell中>/dev/null 2>&1是什么鬼?
- /dev/null 2>&1的意思(可以直接参考shell重定向那篇,/dev/null是空设备)
- shell 中的>/dev/null 2>&1 是什么鬼?
- /dev/null 2>&1的意思(可以直接参考shell重定向那篇,/dev/null是空设备)
- shell中>/dev/null 2>&1是什么鬼?
- >/dev/null 2>&1的意思
- 详解shell中>/dev/null 2>&1到底是什么
- shell 中的>/dev/null 2>&1 是什么鬼?
- shell中>/dev/null 2>&1是什么鬼?
- Difference between 2>&-, 2>/dev/null, |&, &>/dev/null, >/dev/null, 2>&1
- Linux下">/dev/null 2>&1 "相关知识说明
- echo log > /dev/null 2>&1
- Linux下" >/dev/null 2>&1 "相关知识说明
- Shell标准输出、标准错误 >/dev/null 2>&1
- 1>/dev/null and 2>/dev/null意义
- shell中“>/dev/null 2>&1”详解
- Linux Shell 1>/dev/null 2>&1 含义
- >/dev/null 2>&1和&>/dev/null.的区别问题
- :>/dev/null 2>&1 的作用