Linux compresses those things

Source: Internet
Author: User
Tags bz2 gz file

About Tar

There can be only one source file for a Linux compression command, which means that all the files to be compressed must be packaged into a single package before being compressed, and then the package is compressed to complete the compression of multiple files. So before you know how to decompress, you must understand the packaging commands first. Linux packaging is generally done by the tar command, using tar to complete the different actions are done by specifying different parameters, usually using the--x/c, these two parameters, their literal meaning is c--create,x--extract, create and sub-package extraction, There are also some common parameters, such as a to add tar to the end of another tar package, T list the files in the package,-c to switch the working directory to the specified directory, specify this parameter can be extracted from the file into the specified directory. There is also an important parameter F, which can be packaged with the result placed in a file.

tar packaging and unpacking 1. Packaging Files

Package Fiel1,file2,file3 into a file.tar:

TAR-CF File.tar file1 file2 file3

-C Packaging Mode-f Specifies the package results to be created to store files

2. Unpacking Files

Now there is a package file.tar to unpack it:

TAR-XF File.tar

-X Unpacking mode-f Specifies the tar package file

Introduction to Compression software

Gzip was originally created by Jean-loup Gailly and Mark Adler for file compression for Unⅸ systems. We often use files with the. gz suffix in Linux, which are in gzip format. Nowadays it has become a very popular data compression format, or a file format, used on the Internet.

BZIP2 is a lossless compression software based on Burrows-wheeler transform, the compression effect is better than the traditional lz77/lz78 compression algorithm. BZIP2 is capable of high-quality data compression. It uses the advanced compression technology, can compress the ordinary data file 10% to 15%, the compression speed and the pressure efficiency are very high! Supports most compression formats, including TAR, gzip, and more.

The role of compression undoubtedly, once a thing becomes more simple, all aspects of the operation is more simple, Linux compression generally there are several ways, they are gzip compression, BZIP2 compression, XZ compression. Their input is only one, the following is an example, respectively, using the three compression method to compress File.tar, and then compress the compressed file and then use the three different ways to extract, generate Xfile.tar, because of the simple decompression and compression is not the focus of this article, so some parameters are not emphatically introduced, But it will be easy to introduce when needed.

Compression software use 1. Operation with Gzip
Compression: gzip File.tar (compress the file into the specified file, use "Gzip-c File.tar > file.tar.gz") to extract: Gunzip file.tar.gz (compress the file into the specified file, available "Gzip-c File.tar > file.tar.gz ")
2. Operation with Bzip2
Compression: Bzip2-c File.tar > xifle.tar.bz2 decompression: BUNZIP2-CV xfile.tar.bz2 > Xfile.tar
3. Operation with XZ
Compression: Xz-c File.tar > Xfile.tar.xz decompression: unxz-c xfile.tar.xz > Xfile.tar

For compression, the compression rate is clearly the primary concern, in terms of compression ratio, xz>bzip2>gzip, in general, XZ can be higher than bzip2 15% compression ratio, 30% higher than gzip compression ratio, but there are some things in the specific situation still need to care about, such as CPU occupancy, XZ although compression ratio, but it is time-consuming is the most, which means that the use of more CPU time slices, so in the selection of the compression algorithm should also consider the current primary concern is what, in order to choose the compression algorithm.

tar compression and decompression

The two processes described above are packaged and decompressed, but the two processes are separate, and in general, the two processes are not separated, but instead are packaged in a tar package to compress multiple files into a single compressed package. These three compression methods are invoked using the tar command, respectively, to complete one step to compress multiple files into a single compressed package.

1. Use tar to call gzip to generate the File1,file2,file3 and unzip the package.
Compression: TAR-CZVF file.tar.gz file{1,2,3} decompression: TAR-XZVF file.tar.gz
2. Call bzip2 with tar to generate the File1,file2,file3 and unzip the package.
Compression: TAR-CJVF file.tar.gz file{1,2,3} decompression: TAR-XJVF file.tar.gz
3. Use tar to call XZ to generate the File1,file2,file3 and extract the compressed package.
Compression: TAR-CJVF file.tar.gz file{1,2,3} decompression: TAR-XJVF file.tar.gz

For the above text, it is necessary to note that the suffix is not required, the suffix in Linux is not required, this should be a base point, the reason is to specify the suffix name is for the sake of distinction, but also convenient some coarse identification program.

Free to provide the latest Linux technology tutorials Books, for open-source technology enthusiasts to do more and better: http://www.linuxprobe.com/

Linux compresses those things

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.