Shell – stdout and stderr redirection to different files

command lineio-redirectionshellstderrstdout

How can I redirect stdout to 2 different files and stderr to another, different file?

I want something like <my_cmd> 1> file1 file2 2>file3

I know:
<my_cmd> | tee file1 file2 > /dev/null

would redirect stdout to file1 and file2.
But I also want stderr to be redirected to a different file. How can I achieve this?

Best Answer

This should do:

<my_cmd> 2>file3 | tee file1 file2 > /dev/null

The stderr redirection is done first and then tee gets just stdout.