如何在 Linux 中将 txt 转换为 .gz / .z
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5151496/
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
How to convert txt to .gz / .z in Linux
提问by Bharanikumar
In Linux, how to convert txt to .gz / .z and how to view that converted tar file?
在 Linux 中,如何将 txt 转换为 .gz / .z 以及如何查看转换后的 tar 文件?
I tried the command below, but it is not working.
我尝试了下面的命令,但它不起作用。
tar -cf filename.z filename.txt
tar -cf filebane.gz filename.txt
zcat filename.z/gz
I get "bad command error".
我收到“错误命令错误”。
采纳答案by JayM
.Z is typically from compress
. .gz is from gzip
. Tar has nothing to do with it. So, something like this would work to convert .gz to .Z
.Z 通常来自compress
. .gz 来自gzip
. 焦油与它无关。所以,像这样的东西可以将 .gz 转换为 .Z
zcat <file.gz> | compress - > <file.Z>
Or to go the other way:
或者走另一条路:
zcat <file.Z> | gzip > <file.gz>
(zcat should understand the format used by compress)
(zcat应该了解compress使用的格式)
Nowadays, .Z formatted files are rarely seen. That format has been supplanted by gzip and bzip2.
如今,很少看到 .Z 格式的文件。该格式已被 gzip 和 bzip2 取代。
回答by Keith
The tar command does not compress files, it archives them. You can add an option to GNU tar to filter it through gzip. Use tar czf fimename.tar.gz filename.txt
.
tar 命令不会压缩文件,而是将它们归档。您可以向 GNU tar 添加一个选项以通过 gzip 对其进行过滤。使用tar czf fimename.tar.gz filename.txt
.
回答by Kimvais
Do you want to compress or uncompress the files?
您要压缩还是解压缩文件?
To uncompress, do:
gunzip filename.gz
results to an uncompressed file filename
- if the file really IS a gzip compressed file. On most Linuxes, a command file filename.gz
will tell what the file is. For .z
use the command uncompress
要解压缩,请执行:
gunzip filename.gz
结果为未压缩文件filename
- 如果该文件确实是 gzip 压缩文件。在大多数 Linux 上,命令file filename.gz
会告诉你文件是什么。对于.z
使用命令uncompress
For compressing, you can use gzip filename.txt
which results to filename.txt.gz
- if you use compress filename.txt
you'll get filename.txt.z
对于压缩,您可以使用gzip filename.txt
which results to filename.txt.gz
- 如果使用,compress filename.txt
您将获得filename.txt.z