/dev/null 2>&1 详解
2011-11-01 17:20
344 查看
创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。/article/4304021.html
今天一个朋友突然在自己的维护的Linux中, /var/spool/cron/root
中看到了以下的内容:
30 19 * * * /usr/bin/**dcon.sh > /dev/null
2>&1
59 23 * * 1-7 /home/s**-log/squid-log.renew > /dev/null 2>&1
50 1 * * 1-7 /usr/local/src/**log.sh > /dev/null 2>&1
20 2 * * 1-7 /home/sq**-log/**log > /dev/null 2>&1
30 2 * * 1-7 /home/sq**-log/**log.01
30 22 * * * /bin/**sync > /dev/null 2>&1
00 8 * * 1-7 /home/**-log/rmcore > /dev/null 2>&1
00 16 * * 1-7 /home/**-log/rmcore > /dev/null 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 这样的写法.
本文出自 “石头西的Linux博客”
博客,请务必保留此出处/article/4304021.html
今天一个朋友突然在自己的维护的Linux中, /var/spool/cron/root
中看到了以下的内容:
30 19 * * * /usr/bin/**dcon.sh > /dev/null
2>&1
59 23 * * 1-7 /home/s**-log/squid-log.renew > /dev/null 2>&1
50 1 * * 1-7 /usr/local/src/**log.sh > /dev/null 2>&1
20 2 * * 1-7 /home/sq**-log/**log > /dev/null 2>&1
30 2 * * 1-7 /home/sq**-log/**log.01
30 22 * * * /bin/**sync > /dev/null 2>&1
00 8 * * 1-7 /home/**-log/rmcore > /dev/null 2>&1
00 16 * * 1-7 /home/**-log/rmcore > /dev/null 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 这样的写法.
本文出自 “石头西的Linux博客”
博客,请务必保留此出处/article/4304021.html
相关文章推荐
- nohup /dev/null 2>&1 含义详解
- shell之“>/dev/null 2>&1” 详解
- nohup /dev/null 2>&1 含义详解
- /dev/null 2>&1 详解
- /dev/null 2>&1 详解
- shell之“>/dev/null 2>&1” 详解
- /dev/null 2>&1 详解
- 详解shell中>/dev/null 2>&1到底是什么
- /dev/null 2>&1 详解
- /dev/null 2>&1详解
- >/dev/null 2>&1 详解
- /dev/null 2>&1 详解
- Shell: /dev/null 2>&1详解
- shell之“>/dev/null 2>&1” 详解
- shell脚本中/dev/null 2>&1详解
- /dev/null 2>&1 详解
- Shell: /dev/null 2>&1详解
- 相关 /dev/null 2>&1 详解
- /dev/null 2>&1 详解
- Shell脚本———— /dev/null 2>&1详解