For beginners: Linux compression

Source: Internet
Author: User
For beginners, there is only one source file for Linux compression commands. This means that before compression, you have to package all the files to be compressed into one package, and then compress the package, to compress multiple files. So before learning about decompression, you must first know how to press... for beginners, you must note: Linux only has one source file for compressing the Linux compression commands. This means that before compression, you have to package all the files to be compressed into one package, and then compress the package, to compress multiple files. Therefore, you must first understand the packaging command before understanding how to decompress the package. Linux packaging is generally completed through the tar command. man tar can be used to obtain some information. tar is used to complete different operations by specifying different parameters, the two parameters -- x/c are usually used. the literal meanings of these two parameters are c -- create, x -- extract, create and subcontract extraction, and there are also some uncommon parameters, for example, a adds tar to the end of another tar package, t, lists the files in the package,-C, and switches the working directory to the specified directory, by specifying this parameter, you can place the decompressed file to the specified directory. Another important parameter, f, can be packaged in a file. The following two simple examples illustrate packaging and subcontracting extraction: emerge-cf file.tar file1 file2 file3-c, packaging mode,-f specifies the packaging result to be created to store the file. 2.unpack the file. now there is a package of file.tar. Tar-xf file.tar-x: unpack mode.-f specifies the tar package file. After packaging, the compression and compression functions are uncertain. Once a transaction becomes simpler, all operations will be simpler. There are several methods to compress Linux, they are gzip compression, bzip2 compression, and xz compression. Because decompression and compression are not the focus of this article, we will not focus on some parameters, but will briefly introduce them when necessary. 1. use gzip to compress: gzip file.tar (if you want to compress the file to a specified file, you can use "gzip-c file.tar> xxx" to decompress the file, as shown below: gunzip-c file.tar.gz> xfile.tar 2. compress with bzip2: bzip2-c file.tar> xifle.tar.bz2 Unzip: bunzip2-cv xfile.tar.bz2> xfile.tar 3. compress with xz: xz-c file.tar> xfile.tar. unxz-c xfile.tar. xz> xfile.tar for compression, the compression ratio is obviously the primary concern. in terms of compression ratio, xz> bzip2> gzip can generally be 15% higher than bzip2, the compression rate is 30% higher than that of gzip, but there are some other things that need to be concerned in specific situations, such as CPU usage. Although the compression ratio of xz is high, it The time consumed is the most, which means that more CPU time slice is occupied. Therefore, when selecting the compression algorithm, we should also consider the current primary focus, so as to choose the compression algorithm. The packaging and decompression processes are described above, but these two processes are separated. Normally, these two processes are not separated, instead, use the tar package to package and compress multiple files into one compressed package. the following uses the tar command to call these three compression methods to compress multiple files into one compressed package. 1. use tar to call gzip to generate the compressed package tar-czvf file.tar.gz file {1, 2, 3} 2 for file1, file2, and file3. use tar to call bzip2 to generate the compressed package tar-cjvf file.tar.bz2 file {1, 2, 3} 3. use tar to call xz to generate the compressed package tar-cJvf file.tar for file1, file2, and file3. xz file {1, 2, 3} is a bit worth noting for the above text, that is, the suffix name is not a must, and the suffix name in Linux is not a must, this should be a basic point, the reason why suffix names are specified is to facilitate differences and some rough identification programs. After reading the above text, I believe that we should have a certain degree of understanding of Linux compression. In fact, the most important thing is to learn to read man pages. there is everything in it, but it will be too complicated if it is too full, not suitable for beginners.
Related Article

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.