The short answer. You can use either method to accomplish discarding output of your cron job. Here is a more thorough description describing the differences between the two ways of discarding output.
The end result is they both accomplish the same thing (redirecting both file descriptor 1 and 2 to /dev/null). However each method goes about it slightly differently. Both ways have been around for as long as I remember. For your reference read the bash man page on Redirection
Originally Posted by Bash man page section 3.6.4
There are two formats for redirecting standard output and standard error:
Of the two forms, the first is preferred. This is semantically equivalent to
You're basically redirecting both file descriptor 1 (previously stdout) and file descriptor 2 (previously stderr) to write a text stream to /dev/null. You're essentially setting them both without depending on one another.
In the second case,
Originally Posted by Bash man page section 3.6
Note that the order of redirections is significant. For example, the command
ls > dirlist 2>&1
directs both standard output (file descriptor 1) and standard error (file descriptor 2) to the file dirlist
, while the command
ls 2>&1 > dirlist
directs only the standard output to file dirlist
, because the standard error was made a copy of the standard output before the standard output was redirected to dirlist
Basically, you're telling file descriptor 2 (previously stderr) to set the output stream to write to the same location as file descriptor 1 (previously stdout but currently /dev/null) but once they're set they're independent of each other (in your case both file descriptors would be set to /dev/null).
Now let's say you reverse the order...
You just hooked up file descriptor 2 to the current value of file descriptor 1 (currently stdout). Then you set file descriptor 1 (previously stdout) to output to /dev/null. So now what would normally be output to stderr is now being output to stdout and what would normally be output to stdout is discarded to /dev/null. Doing something like this is useful if you want to process stderr by other utilities.
A good example of this would be curl and looking at the REQUEST and RESPONSE http headers in one line.
curl output both stout and stderr normally (shows both HTTP headers and the response body plus some other meta info).
curl -v http://www.google.com
curl discard output only showing stderr (notice that the headers' lines start with either '< ' or '> ').
curl -v http://www.google.com 1> /dev/null
curl hook stderr up to stdout and discard output from file descriptor 1. Use grep to show only the headers.
curl -v http://www.google.com 2>&1 1> /dev/null | grep '^< \|^> '
As you can see from your original question that both accomplish essentially the same thing. However the latter example is flexible and can be used in very interesting ways to manipulate output from the utilities when forming one liner command filters.