注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

天高云淡的博客

A bad beginning makes a bad ending.

 
 
 

日志

 
 

Meaning of /dev/null 2>&1 in Crontab’s Cron Job  

2010-05-24 16:50:15|  分类: CentOS |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
If you use cron job on Linux, some times you want to ignore the output of the command you executed. This can be done by adding “> /dev/null 2>&1” behind the cron job command.

inux was bulit mainly with the C programming language.

In the C programming language a program has three data streams which can be handled separately :
0 means STDIN (STandarD INput) which is usually the keyboard;
1 means STDOUT (STandarD OUTput) which is the monitor;
2 means STDERR (STandarD ERRor) which is usually also the monitor by default.

A program e.g. X by default prints it's output to STDOUT, to the monitor.
In the "X >/dev/null 2>&1" statement, the first part "X >/dev/null" redirects X's output from STDOUT to the /dev/null file which is something like a "bottomless hole" in Linux. What goes there never comes back.
But X's STDERR isn't redirected yet so X's error messages will still be printed to the monitor.
The last part of the statement "2>&1" redirects the STDERR (2) to STDOUT (1) which is already redircted to /dev/null.
So none of them prints to the monitor any more.
(We have to add the "&" sign before the number 1 otherwise STDERR (2) would be redirected to a simple file called 1 in the same directory instead of STDOUT.)

  评论这张
 
阅读(881)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018