The Nineth chapter, file and file system compression and packaging Linux system common compression commands

Source: Internet
Author: User
Tags gpg gz file

Common compression commands for Linux systems:

In Linux, the zip file extension is mostly: "*.tar, *.tar.gz, *.tgz, *.gz, *." Z, *.bz2 "

Linux supports a very high number of compression commands, and different commands use compression techniques that are not the same, and may not be able to compress/decompress files with each other. So, when you download to a compressed file, you naturally need to know what kind of compression command the file is made of, so that it can be used against the decompression! Although the properties of the Linux files are basically not related to the file name, but in order to help us humans, so the appropriate extension is still necessary!

*. 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
BZIP2 gzip name can only be compressed and decompressed for one file!

Tar can "package" many files (directories) into a file that does not provide compression, and later, the GNU program combines tar with compression to provide users with more convenient and powerful compression and packaging capabilities!

Compress

Gzip can unlock files that use compress compression!

[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 Analysis Dependency--Running transaction Check---> Package ncompress.i386 0:4.2.4-47 set to be updated--> finished De Pendency resolutiondependencies resolved======================================================= Package Arch Versi     On Repository size=======================================================installing:ncompress i386 4.2.4-47 Base ktransaction Summary=======================================================install 1 package (s   )<== Last analysis the number of software to install update 0 package (s) Remove 0 packages (s) Total download size:23 kIs this ok [y/n]: y  <== here, 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    

[Email protected] ~]#Compress [-RCV] file or directory<== here is compression [[email protected] ~]#uncompress file. Z <== here is the decompression  options and Parameters:-r: You can also give compression together with the files in the directory! -C: Output the compressed data as standard output to screen-V: Displays the compressed file information and some file name changes during the compression process.  example one: Copy/etc/man.config to/tmp and compress [[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 root 4617 Jan 6 2007/etc/man.config <== Original file-rw-r--r--1 root root 2684 Nov 17:14/tmp/man.config.z <== The compressed file! 

The man.config copied to/tmp is gone! Because it is compressed into a man.config.z, in the default case, the original file that is compressed by compress will disappear, and the compressed file will be created, and the extension will be *. Z.

ll man*-rw-r--r--1 root root 4617 Nov 17:14 man.config

The compressed file does not exist after decompression. If you want to keep the original file and create a compressed file you can use the-c syntax!

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.back.z# -c outputs data from the compression process to the screen instead of writing to # *. Z of the compression file. Therefore, the data can be exported to another file name through a data flow redirection method. 

Compress has been used by very few people because compress cannot unlock *.gz files, and gzip can unlock *. Z's File

gzip, Zcat

Gzip can unlock files that are compressed by compress, zip and gzip software. *.gz

[Email protected] ~]#gzip [-cdtv#] file name [[email protected] ~]#zcat file. Gz options and Parameters:-C: Outputs compressed data to the screen, which can be processed by data flow redirection;-D: the extracted 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 the fastest, but the compression ratio is the worst, 9 slowest, but the best compression! The default is -6 example one: Copy/etc/man.config to/tmp and compress 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 root 2684 Nov 17:24/tmp/man.config.back . z-rw-r--r--1 root root 2057 Nov 17:14/tmp/man.config.gz <== gzip compression better          

In the default state, the original file will be compressed into a. gz file name, and it will no longer exist. Files compressed with gzip in Windows systems can be decompressed by WinRAR this software:

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! 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. gzip-9-C man.config > man.config.gz   

In fact, gzip compression has been optimized, so although Gzip provides 1~9 compression level, using the default 6 is very useful! So the above example four can not be added to that-9 option.

Cat can read the text file, the Zcat can read the text file compressed compressed file! Due to gzip This compression command mainly want to replace compress, so not only compress compressed file can use Gzip to unlock, while zcat this command can simultaneously read compress and gzip compression file!

bzip2, Bzcat

Gzip was developed to replace compress and provide better compression ratios, then bzip2 was developed to replace Gzip and provide a better compression ratio.

[Email protected] ~]#bzip2 [-cdkzv#] File name [[email protected] ~]#bzcat file. Bz2 options 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: To compress just the/tmp/man.config with bzip2 [[email protected] tmp]# # 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# this screen will display MAN.CONFIG.BZ2 the contents of the file after decompression!!  example three: extracting a file from sample one [[email protected] tmp]# bzip2-d Man.config.bz2 example four: The Man.config of example three is compressed with the best compression ratio and retains the original file [[email protected] tmp]# bzip2-9-C man.config > man.config.bz2        
Automatically created with the compress extension as. Z, automatically created as. GZ with the gzip extension. Bzip2 is automatically built with an extension of. bz2!

Bzcat This command can read the content

 

The Nineth chapter, file and file system compression and packaging Linux system common compression commands

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.