On the comparison of compression and decompression command and compression ratio in Linux

Source: Internet
Author: User
Tags bz2 rar

Linux under the compression, decompression command a variety of, unlike in Windows next WinRAR fight all over the world without rival, exclusively. rar. zip format.

For example, the commonly used tar tar.gz tar.bz2 under Linux. Z and so on. The CPU time and compression ratios of each compression and decompression method vary greatly. I would like to list here, I hope the inappropriate, please advise

1 various compression decompression commands demo

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

Packaged Archives:
TAR-CVF Examples.tar Examples (examples is the directory under the Shell execution path)

Release decompression:
TAR-XVF Examples.tar (unzip to the current Shell execution directory)

TAR-XVF examples.tar-c/path (/path extract to Other paths)

(2) tar.gz tgz (tar.gz and tgz are just two different ways of writing, the latter being a simplified writing, equivalent processing)
Linux uses a very common compression method, taking into account the compression time (CPU-consuming) and compressed space (compression ratio)
Actually this is the compression of the GZIP algorithm for (1) The TAR package

Package Compression:
TAR-ZCVF examples.tgz Examples (examples is the directory under the Shell execution path)

Release decompression:
TAR-ZXVF Examples.tar (unzip to the current Shell execution directory)

TAR-ZXVF examples.tar-c/path (/path extract to Other paths)

(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.

Package Compression:
TAR-JCVF examples.tar.bz Examples (examples is the directory under the Shell execution path)

Release decompression:
TAR-JXVF Examples.tar.bz (unzip to the current Shell execution directory)

TAR-JXVF examples.tar.bz-c/path (/path extract to Other paths)

(4) tar.bz2

Faster efficiency than TAR.BZ. The command used is the same as (3) and is not mentioned.

(5). gz
Compression:

gzip-d examples.gz Examples

Extract:

Gunzip examples.gz

(6). Z
Compression:
Compress files

Extract:

Uncompress examples. Z

(7) Tar. Z
Compression:
TAR-ZCVF Examples.tar.z Examples

Extract:
TAR-ZXVF Examples.tar.z

(8). zip
Compression:
Zip-r examples.zip Examples (examples as directory)

Extract:

Zip Examples.zip

(9). rar
Compression:
Rar-a Examples.rar Examples

Extract:

Rar-x Examples.rar

----------------------------------------------------------------------------------------

2 various compression ratios, elapsed time comparison

(1). Tar
TAR-CVF local.tar/usr/local
LOCAL.TAR:892.6MB after packaging, time: s (seconds). After this experiment is packaged. Tar is more than the original file content, unexpectedly!
The compression ratio is 877.7/892.6=0.98 (incredibly not the same, equals 1!) )

TAR-XVF Local.tar
Release 877.7MB (exactly the same size as the original/usr/local, as expected), time consuming: + S, longer than packaging

For. Tar, packaging is faster than releasing, but the packaged. Tar is larger than the original directory content.

(2). tgz
TAR-ZCVF local.tgz/usr/local
LOCAL.TGZ:344.1MB after packaging, time: 146 s (seconds). This experiment illustrates the. tgz compressed to a space below 50%, specifically compression ratio =877.7/344.1 =2.55

TAR-ZXVF Local.tar

Extract 877.7MB, time-consuming: s. This is in contrast to. Tar, where decompression is much more time-saving than packing, close to One-third of the packing time.

(3). tar.bz
TAR-JCVF local.tar.bz/usr/local
After packaging local.tar.bz:318.4 MB time: 5 m (s), very long! )
Compression ratio is 877.7/318.4=2.76

The compression is smaller than the. tgz, but the advantages are not great and the CPU spends more than twice times more time.

TAR-XCVF local.tar.bz
Decompression 877.7 MB, time: S. This is similar to the. tgz, where decompression is much more time-saving than packaging, which is close to One-third of the packing time.

(4). tar.bz2
TAR-JCVF local.tar.bz2/usr/local
local.tar.bz:318.4 MB After packaging time: 302 s

Compression ratio is 877.7/318.4=2.76

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.

If you are concerned about efficiency and you care about your time, choosing tgz tar is a good way to go. Of course, if disk space is more tense, very concerned about space, the choice of high compression ratio of tar.bz2 is more appropriate.

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).

On the comparison of compression and decompression command and compression ratio 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.