Compress files while reading data from STDIN

拜拜、爱过 提交于 2020-01-11 15:04:09

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1758238/compress-files-while-reading-data-from-stdin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!