Reputation: 1274
tee reads from standard input and writes to standard output and a file.
some_command |& tee log
Is that possible for tee to write to a compressed file?
some_command |& tee -some_option log.bz2
If tee can not do that, is there any other command?
I can redirect the output to a compressed file with
some_command |& bzip2 > log.bz2
But with this command, the output to standard output is missing.
Upvotes: 8
Views: 3479
Reputation: 753990
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.
Upvotes: 15
Reputation: 3582
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
)
Upvotes: 6