简体   繁体   English

如何在Linux中将txt转换为.gz / .z

[英]How to convert txt to .gz / .z in Linux

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". 我得到“错误的命令错误”。

使用gzip

gzip filename.txt

.Z is typically from compress . .Z通常来自compress .gz is from gzip . .gz来自gzip Tar has nothing to do with it. 焦油与它无关。 So, something like this would work to convert .gz to .Z 所以,像这样的东西可以将.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. 如今,很少见到.Z格式的文件。 That format has been supplanted by gzip and bzip2. 该格式已被gzip和bzip2取代。

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. 要解压缩,请执行: gunzip filename.gz结果为未压缩的文件文件filename - 如果该文件确实是一个gzip压缩文件。 On most Linuxes, a command file filename.gz will tell what the file is. 在大多数Linux上,命令file filename.gz将告诉文件是什么。 For .z use the command uncompress 对于.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 ,结果是filename.txt.gz - 如果你使用compress filename.txt你会得到filename.txt.z

The tar command does not compress files, it archives them. tar命令不会压缩文件,而是将文件存档。 You can add an option to GNU tar to filter it through gzip. 您可以向GNU tar添加一个选项,以通过gzip过滤它。 Use tar czf fimename.tar.gz filename.txt . 使用tar czf fimename.tar.gz filename.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM