Document compression and packaging

Source: Internet
Author: User

Document compression and packaging

In Windows, we have reached the maximum number of compressed files in the. rar format. However, in linux, such a format cannot be identified. It has its own unique compression tool. But there is a file that can use the. ZIP format under Windows and linux. The benefits of compression do not need to be introduced by the author. I believe you know that it not only saves disk space but also saves network bandwidth during transmission.

Most of the compressed files under linuxare usually end with .tar.gz, except for .tar,. gz,. bz2,. zip, and so on. I have also introduced whether to use the extension name in linux, but it must be included in compressed files. This is to determine which compression tool is used to compress the compressed file, and then decompress the file correctly. The following describes common compression tools with extensions.

. Gz gzip compressed file

. Bz2 bzip2 compressed file

. Tar package file (tar does not have the compression function, but only combines a directory into a file)

.Tar.gz can be understood as packaging with tar and then compressing with gzip

.Tar.bz2 same as above. Pack with tar and then compress with bzip2.


Syntax: gzip [-d #] filename where # Is a number ranging from 1 to 9

-D: used for decompression

-#: Compression level; 1: The worst compression; 9: The best compression; 6: The default value

After test.txt is compressed, it becomes test.txt.gz.

Decompress with-d

Note that gzip cannot compress directories.


Syntax: bzip2 [-dz] filename

-D: Extract

-Z: Compression

In fact, the-z parameter can be omitted. Try again.

Similar to gzip decompression,-d is also used for decompression.


Syntax: tar [-zjxcvfpP] filename

-Z: whether to use gzip compression at the same time

-J: whether to use bzip2 for compression at the same time

-X: unpack or decompress the package.

-T: view the files in the tar package

-C: Create a tar package or compress the file package.

-V: Visualization

-F: followed by the file name. It is followed by the-f file name during compression. This indicates that the compressed file name is filename, while the compressed file is followed by the-f file name, which means to decompress the filename. Note that if there is a combination of multiple parameters with-f, write f to the end.

-P: Use the attributes of the original file and the attributes before compression. (Not commonly used)

-P: You can use an absolute path. (Not commonly used)

-- Exclude filename: do not include the filename file during packaging or compression. (Not commonly used)

. Remember that the-f parameter is followed by the packaged file name.

Delete the original test111directory and unpackage test111.tar. The original file will not be deleted, whether it is packaged or unpacked.

Use gzip to compress the package

Use the-tf package name to view the files in the package or compressed package.

Delete test111 first, and then use tar-zxvf to decompress the. tar.gz compressed package.

-Bzip2 compression can be used for jcvf packaging at the same time. For the -tftype, the compressed package of .tar.bz2 can be used.

-Jxvfdecompress the compressed package of .tar.bz2

-- The exclude parameter is used to filter out certain files during packaging. What if you want to filter multiple files?

It can only be followed by -- exclude filename.

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: 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.