77

I understand that this command attempts to write to nowhere or a null device but what does 2>&1 mean here?

wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1 
1

1 Answer 1

126

2 refers to the second file descriptor of the process, i.e. stderr.

> means redirection.

&1 means the target of the redirection should be the same location as the first file descriptor, i.e. stdout.

So > /dev/null 2>&1 first redirects stdout to /dev/null and then redirects stderr there as well. This effectively silences all output (regular or error) from the wget command.

::edit:: Here is an excellent quick reference for you.

3
  • Thanks. When run in a shared hosting cron job which typically sends an email of the output to an admin, would the > /dev/null 2>&1 prevent this from happening do you think? Also do spaces surrounding '>' matter? Commented Nov 7, 2013 at 17:28
  • Yes, the complete silencing trick is standard practice to make sure that absolutely no output exists to trigger email from a cron job. (Note, however, that the hosting provider may have done all sorts of strange things to your cron environment to make it send some sort of email regardless of your efforts.) ::edit:: And no, spaces around the lone > do not matter, but spaces within the 2>&1 probably do matter (I can't recall). Commented Nov 7, 2013 at 17:32
  • 9
    It might also be worth noting that the same semantics are often achieved with the idiom &>/dev/null Commented Nov 7, 2013 at 17:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.