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.
The tee command, used with a pipe, reads standard input, then writes the output of a program to standard output and simultaneously copies it into the specified file or files. Use the tee command to view your output immediately and at the same time, store it for future use.
Both Linux and UNIX include various commands for Compressing and decompresses (read as expand compressed file). To compress files you can use gzip, bzip2 and zip commands. To expand compressed file (decompresses) you can use and gzip -d, bunzip2 (bzip2 -d), unzip commands.
The gzip program compresses and decompresses files on Unix like system. You need to pass the -c or --stdout , or --to-stdout option to the gzip command. This option specifies that output will go to the standard output stream, leaving original files intact.
What Does tee Command Do in Linux? The tee command reads standard input (stdin) and writes it to both standard output (stdout) and one or more files. tee is usually part of a pipeline, and any number of commands can precede or follow it.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With