What is /dev/null 2>&1?

resting picture resting · May 9, 2012 · Viewed 292.2k times · Source

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  

It's flushing and reloading the firewall.
I don't understand the >> /dev/null 2>&1 part.

What is the purpose of having this in the cron? It's overriding my firewall rules. Can I safely remove this cron job?

Answer

zigg picture zigg · May 9, 2012

>> /dev/null redirects standard output (stdout) to /dev/null, which discards it.

(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 redirects standard error (2) to standard output (1), which then discards it as well since standard output has already been redirected.