General Computing
linux unix zip
Updated Thu, 21 Jul 2022 20:15:27 GMT

On Linux/Unix, does .tar.gz versus .zip matter?


Cross-platform programs are sometimes distributed as .tar.gz for the Unix version and .zip for the Windows version. This makes sense when the contents of each must be different.

If, however, the contents are going to be the same, it would be simpler to just have one download. Windows prefers .zip because that's the format it can handle out of the box. Does it matter on Unix? That is, I tried today unzipping a file on Ubuntu Linux, and it worked fine; is there any problem with this on any current Unix-like operating system, or is it okay to just provide a .zip file across the board?




Solution

Yes, it matters.
Actually, it depends.

tar.gz

  • Stores unix file attributes: uid, gid, permissions (most notably executable). The default may depend on your distribution, and can be toggled with options.
  • Consolidates all files to be archived in one file ("Tape ARchive").
  • Actual compression is done by GZIP, on the one .tar file

zip

  • Stores MSDOS attributes. (Archive, Readonly, Hidden, System)
  • Compresses each file individually, then consolidates the individually compressed files in one file
  • Includes a file table at the end of the file

Because zip compresses the files individually, a zip-archive will most-likely have a larger size (especially with many smaller files - think config files).

So you see, appart from file size, if you zip a bunch of files on Linux/Unix, and then unzip them, the file-attributes will be gone (at the very least those not supported by MS-DOS - depends on what ZIP-software you use). This may matter, or it may not, in which case it doesn't matter (because the file-size difference is in most cases negligible).





Comments (2)

  • +0 – the standard distro of zip on unix-like systems (info-zip) also stores unix file attributes. — Apr 24, 2018 at 21:26  
  • +3 – The ZIP format, e.g. via the Unix zip and unzip utilities, indeed always stores and restores Unix file permissions. Moreover, unzip restores the Unix file timestamps unless you provide the -DD option, and unzip even restores the UID and GID if you provide the -X option. — May 22, 2021 at 02:18