What is the difference between tar and zip? What are the use cases for each?
-
1See these two answers from SuperUser: - Which is more efficient - tar or zip compression? What is the difference between tar and zip? - On Linux/Unix, does .tar.gz versus .zip matter? (By the way, StackOverflow is for programming problems. You'd probably do better asking questions like this at SuperUser in the future)– SomeKittensMay 10, 2012 at 19:35
1 Answer
tar
in itself just bundles files together (the result is called a tarball), while zip
applies compression as well.
Usually you use gzip
along with tar
to compress the resulting tarball, thus achieving similar results as with zip
.
For reasonably large archives there are important differences though. A zip
archive is a collection of compressed files. A gzipped tar is a compressed collection (of uncompressed files). Thus a zip archive is a randomly accessible list of concatenated compressed items, and a .tar.gz
is an archive that must be fully expanded before the catalog is accessible.
- The caveat of a
zip
is that you don't get compression across files (because each file is compressed independent of the others in the archive, the compression cannot take advantage of similarities among the contents of different files); the advantage is that you can access any of the files contained within by looking at only a specific (target file dependent) section of the archive (as the "catalog" of the collection is separate from the collection itself). - The caveat of a
.tar.gz
is that you must decompress the whole archive to access files contained therein (as the files are within the tarball); the advantage is that the compression can take advantage of similarities among the files (as it compresses the whole tarball).
-
3I'm a little confused. The last paragraph and the list seem to contradict each other. A
zip
compresses files into a catalog, but the caveat is that you don't get compression across files? Similarly for.tar.gz
. Is there a typo in there? Jun 26, 2020 at 17:42 -
4
-
What do you mean with
tar.gz
you need to decompress the whole file to access files? I easily dotar -f myfile.tr.gz -xzv file-that-i-want-to-extract.pdf
and it works. Nov 16, 2022 at 2:49 -
2@mariano-daniel A
.tar.gz
file is a gzip-ed tar file, which means tar will have to unzip the.tar.gz
file (possibly in memory) to get to the contained (uncompressed).tar
file, which contains the file you want to ultimately extract. To see, try:gunzip myfile.tar.gz
; you will get the contained (uncompressed)myfile.tar
file (NOTE: gunzip will delete the originalmyfile.tar.gz
file, so you might want to make a backup copy first)– AttilaNov 21, 2022 at 17:54 -
@Attila thanks for clarifying! So
tar
will have to unzip the file, not you ;-) But seriously, now I understand what you meant, I took it too literally and thought you meant I needed to unzip it, then extract from the tar. Have a nice day! Nov 23, 2022 at 3:01