I'm working in Linux environment and want to know about tar and zip commands.
Which is more efficient - tar or zip? I also need to know the differences between the tar and zip commands. Can anyone explain them to me?
|
|
|
|
|||
|
|
|
Efficiency can be measured in different ways:
There are other questions, too, like "How common are the tools to manipulate the resulting archives?" So, for example, |
|||||||||||||||||
|
|
As Wim noted, tar itself doesn't compress. If you do add compress the tar (e.g. to get a .tar.gz or .tar.bz2), you're compressing the whole tar file at once. In contrast, zip compresses each file individually. The efficiency depends on the workload. Specifically, zip allows you to access individual files directly. With tar, you have to first seek through the unwanted (compressed) files before. The compression performance depends on what you're compressing. |
|||||
|
|
As the other already said, tar creates a large "block" of all the files that can be compressed with a stream comrpessor like gzip or bzip2. The disadvantage of this is that you have to decompress the whole file to access one file inside the archive. The advantage of this is that the compress ratio is usually higher, especially when the compressed files are very similar. Other packer like "rar" have a "block mode" (or similar) to have the same effect. |
|||
|
|
|
tar
zip
The fact that zip compresses the files separately will impact compression ratios, particularly on many small similar files. (At least this was exactly correct a decade ago.) |
||||
|
|
|
Tar preserves much more metadata than Zip, see my comparison (it's slightly outdated): (Click to zoom in) Tar passes 65% of the tests, where Zip only passes 17%. I have made the test suite available on github under BSD license so you can try for yourself if you have Mac. For linux there I'm not sure if there are any metadata, so these tests may not be relevant. |
||||