Linux file compression and decompression

Source: Internet
Author: User
Tags gz file

What is a compressed file? What is the principle?

Simply said, is compressed software compressed files called compressed files, the principle of compression is the binary code of the file compression, the adjacent 0,1 code to reduce,

For example, there are 000000, you can turn it into 6 0 60来 reduce the file space, with the understanding of compression is the same principle to restore the data back.

What formats of compressed files are in the Linux environment?

Common compressed files are *.tar,*.tar.gz,*.tgz,*.gz,*. Z,*.BZ2, why are there so many compressed files? This is because Linux supports a very good number of compression commands,

and different commands use compression technology is not the same, of course, before each other may not be able to exchange compression/decompression.

The following are the compression programs for the compressed files in different formats:

650) this.width=650; "title=" image_thumb[2] "style=" BORDER:0PX;WIDTH:421PX;HEIGHT:137PX; "border=" 0 "alt=" Image_ THUMB[2] "src=" Http://img1.51cto.com/attachment/201407/1/8926377_1404232688DemJ.png "height=" 137 "width=" 421 " Hspace= "0" vspace= "0"/>

The common compression commands on Linux are gzip and bzip2, and compress is no longer popular!

Gzip Description:

Use: gzip [options] File name

Options:

650) this.width=650; "title=" image_thumb[6] "style=" border:0px;width:420px;height:140px; "border=" 0 "alt=" Image_ THUMB[6] "src=" http://img1.51cto.com/attachment/201407/1/8926377_1404232688L7K9.png "height=" "width=" 420 " Hspace= "0" vspace= "0"/>

Usage:

1. #gzip filename does not add parameters will delete the original file

2. #gzip –c filename > filename.gz The compressed file redirection output

3. #gzip –d filename.gz will unzip the file

4. #gunzip filename.gz will unzip the file, it will delete the original filename.gz file  

5. #zcat filename.gz to view the file

BZIP2 Introduction:

Use: bzip2 [options] File name

Options:

650) this.width=650; "title=" image_thumb[9] "style=" BORDER:0PX;WIDTH:427PX;HEIGHT:147PX; "border=" 0 "alt=" Image_ THUMB[9] "src=" http://img1.51cto.com/attachment/201407/1/8926377_14042326898ewG.png "height=" 147 "width=" 427 " Hspace= "0" vspace= "0"/>

Usage:

1. #bzip2 filename does not add parameters will delete the original file

2. #bzip2 –c filename > filename.bz2 The compressed file redirection output

3. #bzip2 –d filename.bz2 will unzip the file

4. #bunbzip2 filename.bz2 will unzip the file, it will delete the original filename.bz2 file  

5. #bzcat filename.bz2 to view the file

How do I compress a directory?

The compression program can compress a single file, but cannot compress the directory directly into a compressed file that needs to be packaged before it can be compressed, the packaging command is described here: tar

Tar Introduction:

Options:

650) this.width=650; "title=" image_thumb[12] "style=" border:0px;width:433px;height:162px; "border=" 0 "alt=" Image_ THUMB[12] "src=" Http://img1.51cto.com/attachment/201407/1/8926377_1404232689PKF5.png "height=" 162 "width=" 433 " Hspace= "0" vspace= "0"/>


Usage:

1. #tar-CF Directoryname.tar directoryname Create a package file

2. #tar-zcv-f directoryName.tar.gz directoryname First create a tar package file and then compress it with gzip and display a list of files

3. #tar-zcv-f directoryName.tar.gz directoryname First create a tar package file and then compress it with gzip and display a list of files

4. #tar-ztv-f filename.tar.gz See all the files in a packaged file list

5. #tar Zxv-f filename.tar.gz to unzip with gzip, and then expand the package file to the current directory

6. #tar zxv-f filename.tar.gz–c/tmp with gzip, and then expand the package file to the TMP directory


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.