Linux 从 STDIN 读取数据时压缩文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1758238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:54:15  来源:igfitidea点击:

Compress files while reading data from STDIN

linuxstdincompression

提问by Space

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

在 Linux 上从 stdin 读取时是否可以压缩(创建压缩存档)数据?

采纳答案by Space

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

是的,为此使用 gzip。最好的方法是读取数据作为输入并将压缩后的文件重定向到输出文件即

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

cat test.csvwill 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.

cat test.csv将数据作为标准输出发送,并使用管道符号 gzip 将数据作为标准输入读取。确保将 gzip 输出重定向到某个文件,因为压缩数据不会写入终端。

回答by retracile

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

gzip > stdin.gz也许?否则,您需要充实您的问题。

回答by jtbandes

Yes, gzipwill 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.

是的,gzip会让你这样做。如果您只是运行gzip > foo.gz,它会将 STDIN 压缩到文件 foo.gz 中。您还可以将数据通过管道传输到其中,例如some_command | gzip > foo.gz.