Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to redirect standard output to multiple log files Following seems to be not working. Any help is appreciated.

some_command 1> output_log_1 output_log_2 2>&1

share|improve this question
With zsh, you can use some_command >output_log_1 >output_log_2. – jofel Jun 21 '12 at 8:36

Something like that

echo test | tee file1 file2 file3
share|improve this answer
can the stderr be also redirected in more than one file? – fromnaboo Jun 23 '12 at 9:07
Yes, it can be done by virtue of redirection: find / -name test 2>&1 | tee file1 file2 file3 – akond Jun 23 '12 at 18:27
@akond, cmd 2>&1 | tee log1 log2 I tried executing like above, but i need to press ctrl-c to redirect it to second log file. also the output is printed on the console. I want command output to be redirected to logs but not on the console. any help is appreciated. – doubledecker Jun 25 '12 at 10:34
@doubledecker The tee command writes stdin to file(s) and also to stdout. If you don't want the output to appear on the terminal, you have to redirect to /dev/null like you normally would. – Minix Dec 16 '14 at 8:28
Just a side note: tee has a very useful -a switch, which allows you to append to multiple files, just like >> would. – Erathiel Oct 2 '15 at 10:11

Let's say your output is generated from a function, cmd() :

cmd() {
    echo hello world!

To redirect the output from cmd to two files, but not to the console, you can use:

cmd | tee file1 file2 >/dev/null

This will work for multiple files, given any data source piping to tee:

echo "foobarbaz" | tee file1 file2 file3 file4 > /dev/null

This will also work:

echo $(cmd) | tee file1 file2 >/dev/null

Without the /dev/null redirection, tee will send output to stdout in addition to the files specified.

For example, if this is run from the console, you'll see the output there. Run from a crontab, the output will appear the status message which is mailed to you (also see Gilles' answer here http://unix.stackexchange.com/a/100833/3998).

This worked for me in bash on Ubuntu 12.04, and has been verified in Ubuntu 14.04 using GNU bash 4.3.11(1), so it should work on any recent GNU bash version.

share|improve this answer
@doubledecker -- this looks like it satisfies your conditions, so can be accepted as the answer. Also, +1 as I've tested this under GNU bash (version 4.3.11(1)-release (i686-pc-linux-gnu)) in Ubuntu 14.04. – belacqua Jun 20 '14 at 19:47

Unable to comment, however, another way to express

echo "foobarbaz" | tee file1 file2 file3 file4 file5 file6 file7 file8 > /dev/null

Could be simplified to this, when dealing with many files.

echo "foobarbaz" | tee file{1..8} > /dev/null
share|improve this answer
How is this really different from the other answers already given? Especially since few people likely want literal file1 through file8 as their names and those are likely just example placeholders for the names of the files – Eric Renouf Dec 28 '15 at 14:56
Likely or not, this is exactly the solution I needed, and thought it could help someone else. – user149146 Dec 28 '15 at 19:32

It's an old post but I just found it now...

Instead of redirecting the output to > /dev/null you can redirect it to the last file:

echo "foobarbaz" | tee file1 > file2

Or for appending the output:

echo "foobarbaz" | tee -a file1 >> file2
share|improve this answer
this is more or less what other answer said (except for -a in tee) – Archemar Apr 29 at 9:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.