Linux Common compression Commands-Gzip,zcat,bzip2,bzcat

Source: Internet
Author: User
Tags bz2 gpg uncompress

A few common zip file extensions

*. Z         Compress program compressed files. *.GZ        gzip Program compresses the file. *.BZ2       bzip2 Program compressed files, *.tar       tar program packaged data, and not compressed; *.tar.gz    tar program packaged files, and gzip compressed *.tar.bz2   tar Files that are packaged by the program. and through bzip2 compression.

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 folder  <== Here is the compression[Email protected] ~]#uncompress file. Z  <== here is unzipOptions and Parameters:-r: Can be combined with the file folder under the same time to give compression! -C: Output the compressed data as standard output to screen-V: 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 is missing. Because it is compressed into man.config.z, that is to say. In the default case. Raw files that are compressed by compress will not be visible. The compressed file is created. And the extension will be *. Z. Look carefully, the file from the original 4617bytes reduced to about 2684bytes. There really is a little bit lower.



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 are able to output data as a file name with a data flow redirection method. # for Data flow redirection, we'll talk about it in the 11th chapter of bash specifically! 


Emphasize again. Compress has been used by very few people, since this program cannot unlock *.gz files, and gzip can unlock *. Z file, so assume that your distribution has no compress on it. Then don't do the exercises above.


Gzip,zcat

[Email protected] ~]#gzip [-cdtv#] File name[Email protected] ~]#zcat file name. GZOptions and Parameters:-C: Outputs the compressed data to the screen. Can be handled through data flow redirection. -D: The number of uncompressed parameters;-T: can be used to verify the consistency of a compressed file ~ To see if there are errors;-V: can display the original file/compressed file compression ratio and other information;-#: compression level, 1 fastest. But the compression ratio is the worst,-9 slowest, but the compression ratio is the best!

Default is-6Example One: Copy the/etc/man.config to/tmp. And with gzip compression[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 ratio is better



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# due to man.config This original file is a text file. So we can try to use Zcat to read! # The contents of the file after the Man.config.gz decompression will be displayed on the screen. example Three: Extracting a file from sample one[Email protected] tmp]#gzip-d man.config.gz# do not use gunzip This command, bad back. Use gzip-d to extract the compression. # In contrast to gzip, gzip-d will delete the original. GZ and produce the original Man.config file. example four: The Man.config of the sample three is compressed with the best compression ratio. And keep the original file[Email protected] tmp]#gzip-9-C man.config > Man.config.gz


Cat can read text files. The zcat will be able to read the compressed file of the text file. Since gzip this compression command is primarily intended to replace compress. So not only compress compressed files can be unpacked using gzip. At the same time zcat this command can read compress and gzip compression files at the same time.


Bzip2,bzcat

[Email protected] ~]#bzip2 [-cdkzv#] File name[Email protected] ~]#bzcat file name. bz2Options and Parameters:-C: Outputs the data generated by the compression process to the screen. -D: Uncompressed parameter-K: preserves the original file without deleting the original file OH. -Z: Compression of the parameter-V: can display the original file/compressed file compression ratio and other information;-#: The same as gzip, is in the calculation of compression ratio of the 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# The contents of the file after man.config.bz2 decompression will be displayed on the screen!! Example Three: Extracting a file from sample one [[email protected] tmp]# bzip2-d man.config.bz2 Example four: The Man.config of example three untied Compression with the best compression ratio. And keep the original file [[email protected] tmp]# bzip2-9-C man.config > man.config.bz2


Linux Common compression Commands-Gzip,zcat,bzip2,bzcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.