Mastering Go – Mihalis Tsoukalos

By default, all Unix systems support three special and standard filenames: /dev/stdin, /dev/stdout, and /dev/stderr, which can also be accessed using file descriptors 0, 1, and 2, respectively. These three file descriptors are also called standard input, standard output, and standard error, respectively.

If you want to save both standard output and standard error to the same file, you can redirect the file descriptor of standard error (2) to the file descriptor of standard output (1)! The following command shows this technique, which is pretty common in Unix systems:

$ go run stdERR.go >/tmp/output 2>&1