What happens when you do
some_command >>file 2>>file
is that file will be opened for appending twice. This is safe to do on a POSIX filesystem. Any write that happens to the file when it's opened for appending will occur at the end of the file, regardless of whether the data comes over the standard output stream or the standard error stream.
This relies on support for atomic append write operations in the underlying filesystem. Some filesystems, such as NFS, does not support atomic append. See e.g. the question "Is file append atomic in UNIX?
" on StackOverflow.
Using
some_command >>file 2>&1
would work even on NFS though.
However, using
some_command >file 2>file
is not safe, as the shell will truncate the output file (twice) and any writing that happens on either stream will overwrite the data already written by the other stream.
Example:
$ { echo hello; echo abc >&2; } >file 2>file
$ cat file
abc
o
The hello string is written first (with a terminating newline), and then the string abc followed by a newline is written from standard error, overwriting the hell. The result is the string abc with a newline, followed by what's left of the first echo output, an o and a newline.
Swapping the two echo around wound produce only hello in the output file as that string is written last and is longer than the abc string. The order in which the redirections occur does not matter.
It would be better and safer to use the more idiomatic
some_command >file 2>&1