You can use tee command and something called ‘process substitution’ to pipe the output of a process to several processes at the same time.


The tee command copies standard input to standard output and also to any files given as arguments. A generic example:

<command> | tee <file> | <command>

As an example, if you want to save the output of this find command for future processing but also do some filtering now with this output, you can type:

find . -type f -exec du -a {} + | tee du-files.txt | sort -nr | head -n1

Process substitution

Process substitution allows a process’s input or output to be referred to using a filename. It takes the form of >(COMMAND) or <(COMMAND). We use the first form to provide input for COMMAND from tee. In this case COMMAND needs to be a command that writes to a file, because the output of >(COMMAND) can’t be piped.

Redirecting one output to several processes

You can add one or several process substitutions into tee. The following example is a modified version of the find example:

find . -type f -exec du -a {} + | tee >(gzip -9 > du-compressed.gz) | sort -nr | head -n1
  • We save the output of find (which can be a big file) compressed and, at the same time, we do some filtering.
Test with this online terminal: