Linux Compression tutorial for Beginners

Source: Internet
Author: User
Tags bz2 gz file unpack

Linux can only have one source file for a compressed command, which means that all of the files that are compressed must be packaged into a single package before compression, and then the package will be compressed to complete the compression of multiple files. So before you know how to decompress, you must understand the package command first.

Linux packaging is generally done through the tar command, through the man tar, you can get some information, tar to complete the different actions by specifying different parameters to do, usually using the--x/c, these two parameters, they are literal meaning c--create,x-- Extract, create and subcontract extraction, and there are some less commonly used parameters, for example A, add tar to the end of another tar package, T, list the files in the package,-c, switch the working directory to the specified directory, and specify this parameter to place the extracted files in the specified directory, and so on. There is also an important parameter F, which can be packaged with the result placed in a file.

Here are two simple examples to illustrate packaging and subcontracting extraction:

1. Packaging files, there are now 3 files, file name is Fiel1,file2,file3, the three files packaged into File.tar.

TAR-CF File.tar file1 file2 file3

-C, Packaging mode,-f specifies that the package result to be created will be stored in the file.

2. Unpack the file, now have a package file.tar, unpack it.

TAR-XF File.tar

-X, unpack mode,-f Specifies the tar package file.

Finished packaging, and then compression, the role of compression is beyond doubt, once a thing changed more simple, all aspects of the operation is more simple, Linux compression generally have several ways, they are gzip compression, BZIP2 compression, XZ compression. They have only one input, the following is an example, respectively, using these three compression methods to compress File.tar, and then compress the compressed file respectively with these three ways to decompress, generate Xfile.tar, because of the simple decompression and compression is not the focus of this article, so some parameters are not focused on the introduction, But when needed, it's easy to introduce.

1. Use gzip operation

Compression: gzip File.tar (if you want to compress files into a specified file, use "gzip-c file.tar > XXX" to complete the following)

Decompression: gunzip-c file.tar.gz > Xfile.tar

2. Operate with BZIP2

Compression: Bzip2-c File.tar > xifle.tar.bz2

Decompression: BUNZIP2-CV xfile.tar.bz2 > Xfile.tar

3. Use XZ operation

Compression: Xz-c File.tar > Xfile.tar.xz

Decompression: unxz-c xfile.tar.xz > Xfile.tar

For compression, the compression rate is obviously the primary concern, in terms of compression rate, xz>bzip2>gzip, in general, XZ can be higher than bzip2 15% compression rate, than gzip 30% of the compression rate, but there are some other things in the specific situation or need to care about, such as CPU share, XZ although the compression ratio is high, but it is the most time-consuming, which means that the use of more CPU time slices, so select the compression algorithm should also take into account the current primary concern is what, to choose the compression algorithm.

The above explains the two processes of packing and decompression, but the two processes are separate, and in general, the two processes are not separate, but instead they are packaged into a single compressed package in a single step with the TAR package. The following three compression methods are called using the TAR command respectively to complete a step to package multiple files into a single compressed package.

1. Invoke gzip with tar to generate a compressed package File1,file2,file3

TAR-CZVF file.tar.gz file{1,2,3}

2. Call bzip2 with tar to generate a FILE1,FILE2,FILE3 package

TAR-CJVF file.tar.bz2 file{1,2,3}

3. Call XZ with tar to generate a compressed package File1,file2,file3

TAR-CJVF File.tar.xz file{1,2,3}

For the above text, a bit to note that the suffix name is not necessary, Linux, the suffix is not necessary, this should be a base point, the reason for the designation suffix is to facilitate the distinction, but also to facilitate some rough identification procedures.

Read the above text, I believe that the compression of Linux should have a certain degree of mastery, in fact, the most important thing is to learn to read man page, there are everything, but the whole will be too complex, not very suitable for beginners.

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.