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

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.

  • 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?
    – codecowboy
    Nov 7 '13 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).
    – dg99
    Nov 7 '13 at 17:32
  • 8
    It might also be worth noting that the same semantics are often achieved with the idiom &>/dev/null
    – Joseph R.
    Nov 7 '13 at 17:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.