I want to execute a command, have the output of that command get gzip'd on the fly, and also echo/tee out the output of that command.
i.e., something like:
echo "hey hey, we're the monkees" | gzip --stdout > my_log.gz
Except when the line executes, I want to see this on standard out:
hey hey, we're the monkees
Remove only the gzip suffix from the compressed file name and do not restore the original timestamp if present (copy it from the compressed file). This option is the default when decompressing. Pass the -N option when compressing, always save the original file name and timestamp; this is the default.
If given a file as an argument, gzip compresses the file, adds a ". gz" suffix, and deletes the original file. With no arguments, gzip compresses the standard input and writes the compressed file to standard output.
Another way (assuming a shell like bash
or zsh
):
echo "hey hey, we're the monkees" | tee >(gzip --stdout > my_log.gz)
The admittedly strange >()
syntax basically does the following:
/tmp/
)()
and bind the FIFO to stdin on that subcommandWhat tee
ends up seeing, then, is something like:
tee /tmp/arjhaiX4
All gzip
sees is its standard input.
For Bash, see man bash
for details. It's in the section on redirection. For Zsh, see man zshexpn
under the heading "Process Substitution."
As far as I can tell, the Korn Shell, variants of the classic Bourne Shell (including ash and dash), and the C Shell don't support this syntax.
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