tee to a compressed file tee to a compressed file unix unix

tee to a compressed file


If your shell is bash (version 4.x), you have 'process substitution', and you could use:

some_command 2>&1 | tee >(bzip2 -c > log.bz2)

This redirects standard error and standard output to tee (like |& does, but I prefer the classic notation). The copy of tee's output is sent to a process instead of a file; the process is bzip2 -c > log.bz2 which writes its standard input in compressed format to its standard output. The other (uncompressed) copy of the output goes direct to standard output, of course.


If you're OK having your output on stderr, you can redirect it:

some_command | tee /dev/stderr | bzip2 > log.bz2

This tees the output to both stdout and stderr (| tee /dev/stderr). Then it pipes the stdout to bzip2 (| bzip2 > log.bz2)