How to redirect the standard output (stdout) and the standard error (stderr) to multiple files

In this article I will show you how to redirect the standard output and the standard error to multiple files, with tee.

Watch Free Movies

How to redirect the standard output (stdout) to multiple files:

Using tee: command | tee file1 file2

$ echo "hello" | tee f1 f2
hello

With this tee trick, you can also create multiple copies to files:

This command duplicates the /etc/passwd file to /home/razvan/pwbackup and /root/pwbackup

$ cat /etc/passwd | tee /home/razvan/pwbackup /root/pwbackup

How to redirect the standard error (stderr) to multiple files:

The tee command only accepts the standard output. To redirect the stderr to multiple files, redirect the stderr to stdout first and than use tee: command 2>&1 | tee file1 file2

$ gcc 2>&1 | tee f1 f2
gcc: fatal error: no input files
compilation terminated.

Scroll to Top