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?

  • 4
    Quick'n'dirty : <my_cmd> 1> file1 2>file3; cp file1 file2
    – Httqm
    May 10, 2019 at 14:31
  • @Httqm, please, don't post answers as comments, but as answers which can be voted on. Your suggestion is not at all the same, in particular, there will be no relevant content in file2 until the command finishes!
    – ilkkachu
    May 10, 2019 at 21:54

1 Answer 1


This should do:

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

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

  • 9
    can simplify a touch: cmd 2>file3 | tee file1 >file2 May 10, 2019 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .