How to "tee" stderr

In other words, print on both the screen and to a file (minus stdout)? Thanks again in advance

If your shell is Bash (or similar), this set of redirections will do the job:

$ command 3>&1 1>&2 2>&3 | tee file

What does it mean?

The redirection operator n>&m makes file descriptor n to be a copy of file descriptor m. So, whe are:

  • Opening a new file descriptor, 3, that is a copy of file descriptor 1, the standard output;
  • Making file descriptor 1 a copy of file descriptor 2, the standard error output;
  • Making file descriptor 2 to be a copy of file descriptor 3 (the "backup" of the standard output)

in a short: we swapped the standard output and the standard error output.

Redirect stderr to stdout then redirect stdout to /dev/null and then pipe tee to filename...sequence is important i.e. redirecting stderr to stdout comes before piping stdout to /dev/null. Thogh there is no need for swapping stdout with stderr as the following is ok...

cat valid_filename invalid_filename 2>&1 1>/dev/null | tee output_filename