Compression of Linux Files

Source: Internet
Author: User

Linux has a lot of commands to achieve file compression, but also the existence of various extensions of compressed files. Previously saw these commands and parameters, really do not know which to choose, so the system of learning a bit today, also summed up, I hope to see this blog to help the students.

The article mainly has three parts, what is the file compression, compression command and parameters, packaging and compression of the command and parameters.

One, file compression

What is file compression? Popular point is that the larger file after compression technology, the file becomes smaller. It's like buying a bag of potato chips, and after the gas, the whole bag becomes smaller. So the process of putting the gas in is "compression".

So how do we release the gas from our computer files? Currently we use the computer system are measured in byte units, 1byte = 8bit, each bit is 0 or 1, then if you want to record a number 1, we need 1byte length to represent, that is 0000 0001. Here we can see, a separate representation 1, 1 bits on it, the preceding 7 bits 0 are filled with, these bits can be empty, the compression is to do this can be empty, but the use of the zeros fill placeholder bit clean out, in a more concise way to represent the value of 1. This is just one of the compression techniques, and there are other, for example, 100 consecutive 1, then we may record as "100 1" instead of the true 100 "1" after compression.

Second, the compression of the command and parameters

Know what is file compression, then to specifically look at the compression of Linux commands and parameters.

There are two types of compression commands currently used, Gzip and bzip2.

1. Gzip

Gzip can be said to be the most widely used compression command now. gzip compressed files are *.gz.

Parameters:

-C: Output compressed data in the form of standard output, that is, output to the screen;

-D: the extracted parameters;

-K: Retain the original file, compressed after the existence of two documents, original files and compressed files;

-V: Displays the file name and the compression ratio of each file;

-#: Compression level, 1 fastest, compression ratio lowest,-9 slowest, compression ratio highest.

For compressed text files, you can use the Zcat command to directly view the contents of the file without extracting it.

2, bzip2

BZIP2 is a new generation of compression technology, compressed compared to gzip high. The compressed file is *.bz2. Parameters with gzip are almost identical to gzip parameters, but with an explicit compression parameter-Z.

Three, packaging and compression of the command and parameters

The compression commands described in the previous section compress a single file, so if you want to compress the folder, you need to use the package tar command.

The TAR command is to package multiple directories or files into a large file, which does not have the ability to compress itself, but can compress large files simultaneously with GZIP/BZIP2 support.

Parameters:

1. Function parameters (only one of the functions can appear in the command)

-C: New packaging files;

-T: View the file name contained in the packaged files;

-X: Unpack the file;

-U: Updates the packaged file.

2, support compression parameters

-J: Compression/Decompression through the support of bzip2, the file name is preferably *.tar.bz2;

-Z: Compression/decompression with GZIP support, preferably *.tar.gz file name.

3. Other parameters

-V: Displays the file being processed;

-F: filename of the file after the package;

-C: followed by a specific target directory.

Example:

Compression: Tar-jcv-f yourfilename.tar.bz2 Yourfilename

View: Tar-jtv-f yourfilename.tar.bz2

Decompression: tar-jxv-f yourfilename.tar.bz2-c yourdirectory

Compression of Linux Files

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.