Tee to compressed file

tee reads from standard input and writes to standard output and a file.

some_command |& tee log

Is it possible for tee to write to a compressed file?

some_command |& tee -some_option log.bz2

If te can't do this, is there another team?

I can redirect the output to a compressed file with

some_command |& bzip2 > log.bz2

But with this command, there is no output to standard output.

+5
source share
2 answers

If you're fine with your output to stderr, you can redirect it:

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

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

+4
source

If your shell is bash(version 4.x), you are a "process replacement" and you can use:

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

tee (, |&, ). tee ; bzip2 -c > log.bz2, . , () .

+4

All Articles