Compress files while reading data from STDIN

LinuxStdinCompression

Linux Problem Overview


Is it possible to compress (create a compressed archive) data while reading from stdin on Linux?

Linux Solutions


Solution 1 - Linux

Yes, use gzip for this. The best way is to read data as input and redirect the compressed to output file i.e.

cat test.csv | gzip > test.csv.gz

cat test.csv will send the data as stdout and using pipe-sign gzip will read that data as stdin. Make sure to redirect the gzip output to some file as compressed data will not be written to the terminal.

Solution 2 - Linux

Yes, gzip will let you do this. If you simply run gzip > foo.gz, it will compress STDIN to the file foo.gz. You can also pipe data into it, like some_command | gzip > foo.gz.

Solution 3 - Linux

gzip > stdin.gz perhaps? Otherwise, you need to flesh out your question.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSpaceView Question on Stackoverflow
Solution 1 - LinuxSpaceView Answer on Stackoverflow
Solution 2 - LinuxjtbandesView Answer on Stackoverflow
Solution 3 - LinuxretracileView Answer on Stackoverflow