Linux compression, decompression, and packaging tools

Source: Internet
Author: User
Tags uncompress

Do you ever because a file occupies a large space, and the space shortage of the USB stick can not store this file. Have you ever had too many files in the software to make it easy to copy and carry? Have you ever had a headache because you need backup too fragmented. So the technology based on "file compression and packaging" appears. Below is a description of the tools and use of compression, decompression, and packaging under Linux.



The principle and significance of related terms

1, the principle of compression:

The computer processes the information in the form of binary, and the compression tool is to mark the duplicated string in binary data with special characters, thus achieving the purpose of compressing space.

For example: If your data has 111 ... A total of 10 1 o'clock, then the compression technology is only recorded "10 1", rather than the real 10 1 are recorded, so as to reduce space consumption

2. Decompression

Is the compression of the reverse process, because the compressed file is not directly used by the operating system, so if we want to use compressed file data, then we need to "restore" the compressed file to the state before the uncompressed, this is "decompression"

3, Compression ratio

The proportion of disk space that is consumed by compressed files before and after compression



Second, the advantages of compression technology

1, reduce the space of the file occupied

2, in the file transfer process is not easy to cause file corruption

3, can encrypt the compressed file, protect the file

4, in the application system file backup convenient


Third, in the Linux environment, the compressed file extension is mostly *.tar, *.tar.gz, *.tgz, *.gz, *. Z, *.bz2, *.xz, *.zip

The following are the compression commands for common compressed file extensions

*. Z Compress program zip file

*.gz gzip Program Compressed files

*.BZ2 BZIP2 Program Compressed files

*.XZ XZ Program Compressed files

*.tar files packaged by the TAR program, but not compressed

*.tar.gz tar program packaged files and compressed by gzip program

*.TAR.BZ2 tar program packaged files and compressed by BZIP2 program

*.zip Zip program Compressed files

Tip: In Linux, there is not a fixed program suffix, the suffix is only for the Administrator logo use, convenient for future maintenance.



Four, the following describes the commonly used extensions corresponding to the compression command and use

Common compression commands for Linux systems

Compress: A relatively old compression software, which is used to compare old Unix systems, and now Linux is not commonly used

Gzip: The most widely used compression command to decompress files compressed by software such as compress, zip, and gzip

BZIP2: Lossless compression software based on Burrows-wheeler algorithm transformation

XZ: is a new compressed file with Lzma SDK compression

Zip: is a more general-purpose compression tool, common in linux,windows

Comparison of compression ratio, compression speed and decompression rate

Compress < gzip < bzip2 < XZ


1, Compress, uncompress

Note: Because compress is older, CentOS5.5 is not installed by default, then compress package is ncompress, if the system does not have this command, please perform yum install ncompress installation of this program

Compress [-CV] file or directory <--compression

-C: Output The compressed result to the standard output

-V: Displays compressed file information and file name changes during compression

        uncompress file. Z      <--unzip

Example:[[email protected] tmp]# cp -a /etc/man.config  /tmp/         #拷贝/etc/man.config file to/tmp path, in order to do exercises [[email protected] tmp]# compress  -v man.config             # Compress compression man.config:  -- replaced with man.config.z compression for man.config files:  41.84%    #压缩比 [[email protected] tmp]# lsman.config.z                                         # The compressed file suffix is found by default. Z, it can also be seen that after the compression command is executed, the source file is cleared [[email protected] tmp]# uncompress man.config.z              #解压缩 [[email protected] tmp]#  Lsman.config                                            #解压缩后原压缩的文件会被清除 [[Email protected] tmp]# compress -c man.config  > man.config.Z    #这相当于保留压缩前的文件 [[email protected] tmp]# ll - H-rw-r--r--.  1 root root 4.9k feb 22  2013 man.config-rw-r--r--.  1 root root 2.9k jul 12 13:05 man.config.z   # Can compare compressed files have been compressed and become smaller

Tip: Compress is now rarely used because it cannot decompress compressed files such as *.gz,*.bz2, and subsequent compression programs can decompress *. Package for Z


2, gzip, gunzip, Zcat

gzip [-cdtv#] File name <--compression

-C: Output The compressed result to the standard output, so that the source file can be preserved

-D: equivalent to Gunzip

-T: Can verify the consistency of the compressed files and see if the files are error-free

-V: Displays information about the compression ratio

-#: Specifies the compression ratio, the range 0-9, the larger the number, the greater the compression ratio, but consumes more CPU resources. Default is 6

Gunzip file name. GZ <--Decompression

Zcat file name. GZ <--to view the contents of the Gzip compressed file

Example:[[email protected] tmp]# gzip -v man.config         #压缩文件man .config: 56.5% -- replaced with man.config.gz    #显示压缩比 [[ email protected] tmp]# lsman.config.gz                               #压缩后原文件会被删除 [[email protected] tmp]# gzip -c man.config >  man.config.gz   #这相当于保留压缩前的文件 [[Email protected] tmp]# ll-rw-r--r--.  1 root  root 4940 jul 12 13:23 man.config-rw-r--r--.  1 root root  2184 jul 12 13:27 man.config.gz[[email protected] tmp]# zcat  man.config.gz       #不解压查看gzip压缩的文件的内容 [[email protected] tmp]#  gzip -1 -c man.config &Gt; man.config1.gz [[email protected] tmp]# gzip -9 -c man.config  > man.config9.gz     #压缩比例越高, the smaller the occupied Space [[email protected] tmp]#  Ll-rw-r--r--.  1 root root 4940 jul 12 13:23 man.config-rw-r--r--.  1 root root 2332 jul 12 13:31 man.config1.gz-rw-r--r--.  1  root root 2184 jul 12 13:31 man.config9.gz[[email protected] tmp]#  gzip -d man.config1.gz   #解压缩文件, equivalent to gunzip[[email protected] tmp]#  Lsman.config  man.config1  man.config9.gz

Tip: gzip Cannot compress directories


3, bzip2, BUNZIP2, Bzcat

bzip2 [-cdkv#] File name <--compression

-C: Output The compressed result to the standard output, so that the source file can be preserved

-D: equivalent to Gunzip

-T: Can verify the consistency of the compressed files and see if the files are error-free

-V: Display information such as compression ratio

-K: retains the original file without deleting the original file

-#: Specifies the compression ratio, the range 0-9, the larger the number, the greater the compression ratio, but consumes more CPU resources. Default is 6

BUNZIP2 file name. bz2 <--Decompression

Bzcat file name. Bze <--to view the contents of bzip2 compressed files

Example:[[email protected] tmp]# bzip2 -v man.config   man.config:   2.251:1,  3.555 bits/byte, 55.57% saved, 4940 in, 2195 out.      #压缩比, speed and other information [[email protected] tmp]# lsman.config.bz2[[email  protected] tmp]# bzip2 -d man.config.bz2   #解压缩, equivalent to bunzip[[email protected]  tmp]# lsman.config[[email protected] tmp]# bzip2 -9 -k man.config    #-k parameter compression retains original file [[Email protected] tmp]# ll-rw-r--r--.  1 root  Root 4940 jul 12 13:23 man.config-rw-r--r--.  1 root root 2195  Jul 12 13:23 man.config.bz2[[email protected] tmp]# bzcat  man.config.bz2     #不解压查看bzip2压缩后的文件内容 [[email protected] tmp]# bzip2 -c  man.config > man.config2.bz2 [[email protected] tmp]# lsman.config  man.config2.bz2   man.config.bz2

Tip: bzip2 cannot compress the directory


4, XZ, UNXZ, Xzcat

XZ [-cdkv#] File name <--compression

The usage of each parameter is like BZIP2, which is no longer detailed here

UNXZ filename. XZ <--Decompression

Xzcat file name <--to view XZ compressed file contents

 exercises: [[Email protected] tmp]# xz -v man.config  man.config  (1/1)   100.0 %                    2,204 B / 4,940 B =  0.446     #压缩比信息 [[email protected] tmp]# xz -c man.config  > man.config.xz     #这相当于保留压缩前的文件 [[email protected] tmp]#  Ll-rw-r--r--.  1 root root 4940 jul 12 13:23 man.config-rw-r--r--.  1 root root 2204 jul 12 14:18 man.config.xz[[email protected]  tmp]# unxz man.config.xz        #解压缩, equivalent to xz -d [[ Email protected] tmp]# ll-rw-r--r--.  1 root root 4940 jul 12  13:23 man.config 


5, Zip, unzip

Zip Zipfile.zip src_file .... <--compression

Note: Zip can archive the directory for compression

Unzip Zipfile.zip <--Decompression

Exercise: [[email protected] tmp]# cp-r/home/*/tmp/home/#将home下文件拷贝到/tmp directory [[email protected] tmp]# Ls/home/user1 user2[  [Email protected] tmp]# zip home.zip home/* #对目录进行压缩 adding:home/user1/(stored 0) adding:home/user2/(stored 0%) [[email protected] tmp]# Lshome home.zip

Archive compression for catalogs typically uses the Tar tool, so zip is no longer introduced here



Five, packaging archiving tools

Tar: Packaged Archive tool

can be implemented to package multiple files into a single file, which is an archive file, but tar is only archived, not compressed

1. Create an archive

tar [-CVF] Tarfile.tar filename

-c:create, new package file

-V: Displays the file name being processed during the compression/decompression process

-F filename:-f must be followed by the processed file name, it is recommended that-F use a single parameter

[Email protected] tmp]# tar-cv-f/tmp/home.tar/home[[email protected] tmp]# Ls/tmp/home.tar

2. Expand Archive

tar [-XVF] Tarfile.tar

-X: Decompression function

-V: Displays the file name being processed during the compression/decompression process

-F filename:-f must be followed by the processed file name, it is recommended that-F use a single parameter

[Email protected] tmp]# TAR-XVF home.tar[[email protected] tmp]# lshome Home.tar

3. See which files are included in the archived file

tar [-TF] Tarfile.tar

-T: See what file names are included in the package file

-F filename:-f must be followed by the processed file name, it is recommended that-F use a single parameter

[Email protected] tmp]# TAR-TF Home.tar

4. Tar and compression tools (gzip, bzip2, XZ) to perform compression

tar [-ZJJ] Tarfile.tar

-Z: Compression/decompression using gzip, this file name is preferably *.tar.gz

-j: Use bzip2 for compression/decompression, preferably *.tar.bz2 for this file name

-j: Using XZ for compression/decompression, this file name is preferably *.TAR.XZ

[[email protected] tmp]# TAR-ZCVF home.tar.gz home[[email protected] tmp]# lshome Home.tar home.tar.gz


Vi. Summary of Orders

1, the Linux system commonly used compression command: Compress,gzip,bzip2,xz,zip

Where COMPRESS,GZIP,BZIP2,XZ cannot compress the directory, typically used with the TAR Archive Packaging tool to archive the directory

Zip files can be compressed directly to the directory

2. Package Archive Tool: Tar

Create archive parameters: [-CVF]

Expand archive parameters: [-XVF]

View archived file parameters: [-TF]]

The tar and compression tools work with parameters: [-ZJJ]


This article is from the "Crab Learn Linux" blog, please be sure to keep this source http://windchasereric.blog.51cto.com/5419433/1674824

Linux compression, decompression, and packaging tools

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.