Comparison of compression and decompression commands used in Linux

Source: Internet
Author: User
Tags bz2

The commonly used formats are:
Tar, tar.gz (tgz), tar.bz2,

In different ways, the compression and decompression of the CPU time and compression ratio is also very different.

1. Tar
Just packaging action, equivalent to archive processing, do not compress, decompression is the same, just to release the archive file.

(1) Packaging archive format:

Tar-CVF examples.Tarfiles|dir#说明:-C,--Create a new archive creates an archive file-V,--verbose verbosely list files processed shows the process of creating an archive file-F,--file=archive Use ARCHIVEfileor device ARCHIVE immediately after the file name to be processed, such as--file=examples.Tar#举例:Tar-cvffile.Tarfile1 #file1文件Tar-cvffile.Tarfile1 file2 #file1, file2 fileTar-cvffile.Tar dir#dir目录

(2) Release the decompression format:

tar -xvf examples. Tar (unzip to the current directory) tar -xvf examples. Tar  -c/path (/path decompression to other path) #说明:-X,--extract, extract files from an archive extract file from one archive # example:tar  file. Tar Tar file. tar -c/temp  #解压到temp目录下

2. tar.gz tgz (tar.gz and tgz are just two different ways of writing, the latter being a simplified writing, equivalent processing)
This format is a very common type of compression used under Linux,
Compact time (CPU-intensive) and compressed space (compression ratio)
Actually, this is the compression of the GZIP algorithm for the TAR package.

(1) Packaging compression format:

tar -ZCVF examples.tgz Examples (examples directory under current execution path) Description:-Z,--gzipgzip  Archive files in the form of gzip compression example:tarfiledir #dir目录

(2) Release the decompression format:

tar -zxvf examples. Tar (unzip to the current execution directory) tar -zxvf examples. Tar  -c/path (/pathdecompression to another path) example:tarfile. tgztarfile. tgz-c/ Temp

3 tar.bz

The compression ratio in Linux is larger than tgz, which takes up less space after compression, making the compression package look smaller.
But at the same time in the compression, decompression process is very CPU-intensive time.

(1) Packaging compression format:

tar -jcvf examples. Tar . bz2 examples   (Examples is the directory under the current execution path) Description:-j,--bzip2bzip2  archive files in the form of bzip2 compression example:tar  File. Tar dir #dir目录

(2) Release decompression:

tar -jxvf examples. Tar . BZ2 (unzip to the current execution directory) tar -jxvf examples. tar. bz2  -c/path (/pathdecompression to another path) example:tarfile.  Tar. bz2tarfile. tar. Bz2-c/temp

4 GZ
Compression:
gzip-d examples.gz Examples

Extract:
Gunzip examples.gz


5 zip
Zip format is open and free, so widely used in Windows, Linux, MacOS platform, to say zip has any shortcomings, that is, it is not very high compression ratio, such as RAR and tar.gz format.
Compression:
Zip-r examples.zip Examples (examples as directory)

Extract:
Zip Examples.zip

6. rar
Compression:
Rar-a Examples.rar Examples

Extract:
Rar-x Examples.rar

Compression ratio, elapsed time comparison

In order to ensure that the compression ratio is more obvious, you need to choose a more content, occupy a larger directory as the test of this experiment.
Find a directory of about 23G to test, first of all to be clear due to the implementation of environmental changes, error is unavoidable

First, define a concept:
Compression Ratio = original content size/compressed size, the larger the compression ratio, the smaller the compressed package that occupies space after compression

. tar

  packaging:  time  tar -CVF test.     tar /usr/test time: Real 3m20.709suser 0m3.477ssys 0m42.595s size: Before Packaging:  23214680   after Packaging:  Span style= "COLOR: #800080" >22202984   time: 3m20.709s compression ratio:  22202984 /23214680   unzip:  time  tar -xvf test.tar   size: Before extracting:  22202984   after decompression:  23211064   time: Real 2m47.548suser 0m4.999ssys 1m14.186s  

. tgz

Package Compression:  Time tar -zcvf test.tgz/usr/test time: Real    16m30.767suser    16m1.394ssys     1m7.391s size: Before Packaging:  23211064 after Packaging:18949032 Time: Compression ratio: Unzip:tar -zxvf test. Tar size: Before decompression: 18949032 after decompression: 23211064 time: Real    3m52.418suser    2m46.325ssys     1m21.442s

. tar.bz2

Package Compression:  Time tar -JCVF test. tar. bz2/usr/Test time: Real    80m39.422suser    80m14.599ssys     0m58.623s size: Before Packaging:  23211064 after Packaging:18728904 time: 80m39.422s compression ratio: Unzip:TimingTar - JXVF test. Tar . bz2 time: Real    27m54.525suser    27m44.108ssys     1m43.645s size: Before decompression:18728904  After decompression:23211064

Results, Preliminary Conclusions:

Combined, on the compression ratio: Tar.bz2>tgz>tar
The occupancy space is inversely proportional to the compression ratio: Tar.bz2<tgz<tar
Time consuming (packing, extracting)
Package: Tar.bz2>tgz>tar
Decompression: tar.bz2>tar>tgz
In terms of efficiency, of course, it takes time to be as short as possible.

Therefore, Linux under the occupation space and time-consuming trade-offs more choice of tgz format, not only high compression rate, and packaging, decompression time is relatively fast, is an ideal choice.

Conclusion:

Once again confirms the contradiction between physical space and time (want to occupy a smaller space, get a high compression ratio, it must sacrifice a long time; conversely, if the time is more valuable, fast, then the resulting compression ratio must be small, of course, will occupy more space).

Comparison of compression and decompression commands used in Linux

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.