Several common Linux compression commands tar,gz,zio,bz2

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. Here I would like to enumerate, I hope the inappropriate, please advise. ---------------------------------------------------------------------------------------------1 Various Compression decompression commands demo (1) Tar only does the packing action, the equivalent of the archive processing, does not compress; Unzip the same, just release the archive file.

Packaged Archive: TAR-CVF Demo.tar Demo (Demo for directory, file path required to be archived, Demo.tar stored in the current script execution directory) TAR-CVF Demo.tar demo1 demo2 Demo3 (demo1,dem O2,DEMO3 archive to a directory)

Release decompression: TAR-XVF Demo.tar (unzip to current shell execution directory) TAR-XVF demo.tar-c/path (/path extract to Other path)

(2) tar.gz tgz (tar.gz and tgz are just two different ways of writing, the latter is a simplified writing, equivalent processing) used in Linux under 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 demo.tgz (Demo is the directory under the Shell execution path)

Release decompression: TAR-ZXVF Demo.tar (unzip to current shell execution directory) TAR-ZXVF demo.tar-c/path (/path extract to Other path)

(3) tar.bz Linux compression ratio is larger than tgz, that is, the compression takes up less space, 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 demo.tar.bz Demo (demo is the directory under the Shell execution path)

Release decompression: TAR-JXVF demo.tar.bz (unzip to current shell execution directory) TAR-JXVF demo.tar.bz-c/path (/path extract to Other path)

(4) TAR.BZ2 has faster efficiency than tar.bz. The command used is the same as (3) and is not mentioned.

(5). GZ Compression: gzip-d demo.gz Demo

Decompression: Gunzip demo.gz

(6). Z compression: Compress files

Decompression: uncompress demo. Z

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

Decompression: TAR-ZXVF Demo.tar.z

(8). zip Compression: Zip-r demo.zip Demo (Demo for directory)

Unzip: Zip Demo.zip

(9). RAR Compression: Rar-a Demo.rar Demo

Decompression: Rar-x Demo.rar----------------------------------------------------------------------------------------2 Various compression ratios, time-consuming comparisons

In order to ensure that the compression ratio is more obvious, you need to choose a more content, occupy a larger directory as a demo. I have my own Ubuntu 9.10/user/local the entire directory as an example,/user/local all the files in total size is 877.7MB.

Here, we define the compression ratio = original content size/compression size, the larger the compression ratio, the smaller the compressed space-consuming compression packet

(1). Tar tar-cvf local.tar/usr/local packaged LOCAL.TAR:892.6MB, time-consuming: s (s). 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 After packing LOCAL.TGZ:344.1MB, time: 146 s (s). This experiment illustrates the. tgz compressed to a space below 50%, specifically compression ratio =877.7/344.1 =2.55

TAR-ZXVF Local.tar Decompression 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 after packaging local.tar.bz:318.4 MB time: 302 s compression ratio is 877.7/318.4=2.76

Results, Preliminary Conclusions:

Combined, on the compression ratio: the Tar.bz2>tgz>tar occupies an inverse proportion to the compression ratio: Tar.bz2<tgz<tar time-consuming (packing, unpacking) Packaging: Tar.bz2>tgz>tar Decompression: Tar.bz2>tar>tgz from an efficiency standpoint, of course, the shorter the better.

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). In general, there will not be much impact: individuals generally like to use: tar.gz compression

Several common Linux compression commands tar,gz,zio,bz2

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.