How to convert txt to .gz / .z in Linux
In Linux, how to convert txt to .gz / .z and how to view that converted 开发者_StackOverflowtar file?
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".
Use gzip
:
gzip filename.txt
.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
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)
Nowadays, .Z formatted files are rarely seen. That format has been supplanted by gzip and 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. On most Linuxes, a command file filename.gz
will tell what the file is. For .z
use the command 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
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
.
精彩评论