什么是/dev/null 2& 1? [英] What is /dev/null 2>&1?
问题描述
我在/etc/cron.daily/apf中找到了这段代码
I found this piece of code in /etc/cron.daily/apf
#!/bin/bash
/etc/apf/apf -f >> /dev/null 2>&1
/etc/apf/apf -s >> /dev/null 2>&1
正在刷新并重新加载防火墙.
我不理解>> /dev/null 2>&1
部分.
It's flushing and reloading the firewall.
I don't understand the >> /dev/null 2>&1
part.
将其放在cron中的目的是什么?它覆盖了我的防火墙规则. 我可以安全地删除此Cron作业吗?
What is the purpose of having this in the cron? It's overriding my firewall rules. Can I safely remove this cron job?
推荐答案
>> /dev/null
将标准输出(stdout
)重定向到/dev/null
,并丢弃它.
>> /dev/null
redirects standard output (stdout
) to /dev/null
, which discards it.
(>>
似乎是多余的,因为>>
表示追加,而>
表示截断和写入,并且追加或写入/dev/null
具有相同的净效果.我通常只使用
(The >>
seems sort of superfluous, since >>
means append while >
means truncate and write, and either appending to or writing to /dev/null
has the same net effect. I usually just use >
for that reason.)
2>&1
将标准错误(2
)重定向到标准输出(1
),由于标准输出已被重定向,该错误也会被丢弃.
2>&1
redirects standard error (2
) to standard output (1
), which then discards it as well since standard output has already been redirected.
这篇关于什么是/dev/null 2& 1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!