Compress files while reading data from STDIN

Space picture Space · Nov 18, 2009 · Viewed 103.2k times · Source

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

Answer

Space picture Space · Nov 18, 2009

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.