什么是/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屋!