Is it possible to pipe a command output to bzip2 for compression to an output file?
Something along the lines of:
cat somefile.txt | bzip2 --output somefile.txt.bz2
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityYou can do this with bzip2
's -c
option:
-c --stdout
Compress or decompress to standard output.
For example:
command | bzip2 -c > some.txt.bz2
And to decompress:
bzip2 -dc < some.txt.bz2 | less
The bzip2 utility will compress stdin but won't write it to stdout if stdout is a terminal. You can though use standard output redirection techniques.
command | bzip2 >somefile.txt.bz2
and to read it the usual tools are available e.g.
bzless somefile.txt.bz2