A few common zip file extensions
*. Z Compress program compressed files; *.gz gzip program compressed files; *.bz2 bzip2 Program compressed files; *.tar tar program packed data, not compressed; *.tar.gz Tar The files packaged by the program, and the files that are packaged in the zipped *.tar.bz2 tar program, which are compressed by the bzip2
|
Compress
[Email protected] ~]#Yum Install ncompressBase 100% |=========================| 1.1 KB 00:00updates 100% |=========================| 951 B 00:00addons 100% |=========================| 951 B 00:00extras 100% |=========================| 1.1 KB 00:00setting up install processparsing package Install argumentsresolving Dependencies<== Start analyzing dependencies-Running Transaction Check---> Package ncompress.i386 0:4.2.4-47 set to be updated--> finished Dependency Reso Lutiondependencies resolved======================================================= Package Arch Version Reposi Tory size=======================================================installing:ncompress i386 4.2.4-47 base Ktransaction Summary=======================================================install 1 package (s)<== Final analysis of the number of software to be installedUpdate 0 Package (s) Remove 0 package (s) Total download size:23 kIs this ok [y/n]:y <== here, please press Y to confirm the installation.Downloading Packages: (1/1): ncompress-4.2.4-47 100% |=========================| KB 00:00warning:rpmts_hdrfromfdno:header V3 DSA signature:nokey, key ID e8562897importing GPG key 0xe8562897 "Cen TOS-5 Key (CentOS 5 official Signing key) <[email protected]> "from http://mirror.centos.org/centos/ Rpm-gpg-key-centos-5is this OK [y/n]:y <== here is related to the digital signature .Running rpm_check_debugrunning Transaction testfinished Transaction testtransaction Test succeededrunning Transaction Installing:ncompress ######################### [1/1]installed:ncompress.i386 0:4.2.4-47complete!
|
[Email protected] ~]#compress [-RCV] file or directory <== Here is the compression[Email protected] ~]#uncompress file. Z <== here is unzipOptions and Parameters:-r: You can also give compression together with the files in the directory! -C: Output the compressed data as standard output to the screen-V: You can show the compressed file information and some file name changes during the compression process. Example One: Copy the/etc/man.config to/tmp and compress it[Email protected] ~]#cd/tmp[Email protected] tmp]#Cp/etc/man.config.[Email protected] tmp]#compress-v Man.configMan.config:--Replaced with man.config.z Compression:41.86%[[email protected] tmp]#ls-l/etc/man.config/tmp/man*-rw-r--r--1 root root4617Jan 6 2007/etc/man.config<== Original File-rw-r--r--1 root root2684Nov 17:14/tmp/man.config.z<== the compressed file!
|
I do not know if you have found that the copy to/tmp Man.config disappeared! Because it is compressed into man.config.z. In other words, in the default case, the original file that is compressed by compress is not visible, and the compressed file is created and the extension is *. Z. Take a closer look at the file from the original 4617bytes down to about 2684bytes, indeed there is a reduction.
example two: Unlock the zip file you just got uncompress man.config.z ll man*-rw-r--r--1 root root 4617 Nov 17:14 man.config
|
example Three: compressing the man.config into another file to back up compress-c man.config > Man.config.back.z ll man*-rw-r--r--1 root root 4617 Nov 17:14 man.config-rw-r--r--1 root root 2684 Nov 17:24 Man.config.bac K.z# This-C option is more interesting! He will output the compression process data to the screen instead of writing it into # *. Z of the compression file. So, we can export the data to another file name through a data flow redirection method. # for Data flow redirection, we'll talk in detail in the 11th Chapter bash!
|
Again, compress has been used by very few people because the program cannot unlock *.gz files, and gzip can unlock *. Z file, so if you don't have compress on top of your distribution, don't do the exercises above.
Gzip,zcat
[Email protected] ~]#gzip [-cdtv#] File name[Email protected] ~]#zcat file name. GZOptions and Parameters:-C: Output the compressed data to the screen, can be processed by the data stream redirection;-d: the extracted parameters;-T: can be used to verify the consistency of a compressed file ~ To see if there is a bug;-V: Can show the original file/compressed file compression ratio and other information;-#: compression level,- 1 the fastest, but the compression ratio is the worst,-9 the slowest, but the best compression ratio! Default is -6Example One: Copy the/etc/man.config to/tmp and compress it with gzip[Email protected] ~]#cd/tmp[Email protected] tmp]#Cp/etc/man.config.[Email protected] tmp]#gzip-v Man.configman.config:56.1%--Replaced with man.config.gz[[email protected] tmp]#ll/etc/man.config/tmp/man*-rw-r--r--1 root root 4617 Jan 6 2007/etc/man.config-rw-r--r--1 root root2684Nov 17:24/tmp/man.config.back.z-rw-r--r--1 root root2057Nov 17:14/tmp/man.config.gz<==gzip compression is very good
|
example two: Because the man.config is a text file, please read the contents of the compressed file of example one! [Email protected] tmp]#Zcat man.config.gz# because Man.config this original file is a text file, so we can try to use Zcat to read! # At this point the screen will show the contents of the file after man.config.gz decompression! example Three: Extracting a file from sample one[Email protected] tmp]#gzip-d man.config.gz# Don't use gunzip this command, bad back! Use gzip-d to decompress! # In contrast to gzip, gzip-d will delete the original. GZ and produce the original Man.config file. example four: Man.config with the best compression ratio and retains the original file[Email protected] tmp]#gzip-9-C man.config > Man.config.gz
|
Cat can read the text file, the Zcat can read the text file compressed compressed file! Since gzip this compression command mainly wants to replace compress, so not only compress compressed files can be unpacked using gzip, while zcat this command can simultaneously read compress and gzip compression file.
Bzip2,bzcat
[Email protected] ~]#bzip2 [-cdkzv#] File name[Email protected] ~]#bzcat file name. bz2Options and Parameters:-C: Output the data generated by the compression process to the screen! -D: decompressed parameter-K: preserves the original file without deleting the original file Oh! -Z: Compression parameter-V: can display the original file/compressed file compression ratio and other information;-#: Same as gzip, all in the calculation of compression ratio parameters, 9 best,-1 fastest! Example One: Compress just the/tmp/man.config with bzip2[Email protected] tmp]#bzip2-z Man.config# At this time Man.config will become man.config.bz2! Example Two: Read the file contents of sample one! [Email protected] tmp]#Bzcat man.config.bz2# At this point the screen will show the contents of the file after the MAN.CONFIG.BZ2 decompression!! example Three: Extracting a file from sample one[Email protected] tmp]#bzip2-d man.config.bz2example four: Man.config with the best compression ratio and retains the original file[Email protected] tmp]#bzip2-9-C man.config > man.config.bz2
|
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux Common compression Commands-Gzip,zcat,bzip2,bzcat