113

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?

1
  • 1
    Note that tar files may also be compressed with other, more modern compressors (like gzip replaced the original "compress" program as it was much more efficient). The file name ending changes accordingly. Commented Oct 3, 2020 at 13:13

9 Answers 9

82

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 (TAR: "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).

Note:
Apparently, modern versions of ZIP also store Unix-file-attributes (depends on your ZIP-software), so with modern-zip-software, the file-size will be the only difference.

2
  • 21
    the standard distro of zip on unix-like systems (info-zip) also stores unix file attributes. Commented Apr 24, 2018 at 21:26
  • 5
    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.
    – caw
    Commented May 22, 2021 at 2:18
40

tar gz is better for Linux/Unix as it retains permissions, such as "executable" on scripts.

2
  • 12
    OS X's Archive Utility and zip / unzip preserve permissions, but there might be other utilities that don't.
    – Lri
    Commented Jan 19, 2013 at 15:33
  • 8
    Standard zip/unzip tools (info-zip) retain permissions on linux, and timestamps on windows. see: en.wikipedia.org/wiki/Info-ZIP for typical capabilities... which overcomes the permissions issues and file size limitations while retaining desirable random access and editable archive properties. Commented Apr 24, 2018 at 21:23
36

Most popular Linux distros these days are by default equipped with zip compatibility. But as stated by nc3b, tar and gzip are more common on Linux/Unix systems. If you need 95% compatibility on these systems, consider using tar and gzip. If you need only 85%, zip will do fine.

8
  • 4
    Okay, 95% is better than 85% :-) A very minor question, does it matter at all if the file extension is .tgz instead of .tar.gz?
    – rwallace
    Commented May 29, 2010 at 19:34
  • 10
    Extension doesn't matter at all, it's just used for reference by users and programs. If the extension is .XXX and you know it's .tar, you could still use tar to untar it. .tgz and .tar.gz are both in fact the same extensions and files with these extensions would be similar.
    – Pylsa
    Commented May 29, 2010 at 19:43
  • 2
    On the other hand, for 100% compatibility on Windows you would need to use cab.
    – kinokijuf
    Commented Nov 15, 2011 at 17:39
  • 3
    tar will store uid, gid and permissions, such as +x on unix systems. zip stores archive, readonly, hidden and system on windows systems. Commented Oct 30, 2013 at 21:43
  • 1
    @mtak you can always just use gunzip --suffix .zip npm-debug.log.zip or gunzip -c < npm-debug.log.zip > npm-debug.log Commented Jan 19, 2017 at 13:14
30

tar/gzip is a pretty crappy format since the archive cannot be randomly accessed, updated, verified or even appended to... without having to decompress the entire archive.

zip is much better in that regard.... you can quickly obtain the contents of a zip file, append to it without recompressing the first part, etc.

zip has some size limitations ... depending on the version of "zip" that you use... and these can be a problem. but the standard info-zip tool that comes with most linux-like os'es has no size limitations and preserves file permissions just fine.

see: https://en.wikipedia.org/wiki/Info-ZIP for capabilities

2
  • What kind of limitations are you talking about?
    – Pacerier
    Commented Apr 24, 2014 at 11:34
  • edited and provided a link Commented Apr 24, 2018 at 21:29
11

Barebones Unix installs don't contain unzip (i.e. server installs), but they always contain tar and gzip. If your audience is servers, I'd go for gzip.

Also gzip has greater compression than zip, so the file will be smaller.

4
  • 3
    I wouldn't say gzip compresses better than ZIP. Both use the same DEFLATE algorithm, and all comparisons I've done give similar results in file size. Commented May 29, 2010 at 21:57
  • 7
    Well, tar.gz will compress the whole file in one go, whereas zip compresses files individually. For many small files, the first approach will usually generate noticeably smaller files, because redundancies can be used across files. The difference is not huge though.
    – sleske
    Commented Jun 24, 2010 at 16:09
  • 4
    @sleske actually gzip has a pretty small window size (32K) for finding redundancies, it's not the whole file Commented Mar 3, 2021 at 17:31
  • 1
    To drive home sleske's point: compressing a tar is equivalent to what's called a 'solid' archive for RAR, 7-zip, PowerArchiver and pretty much every other non-crappy archiver out there. .tgz and .zip simply don't give you the choice. Better archivers also offer features like deduplication and advanced codecs, which can improve compression by an order of magnitude on average (i.e. in actual daily use, not only in benchmarks).
    – DarthGizka
    Commented Oct 30, 2021 at 19:00
7

Yes, it matters. Tar is an archiver. And in tar.gz, we compress that archive.

Zip is both an archiver and compressor.

If you compare compression, from my experience, gzip is much better than zip.

And the other significant difference is mentioned in another answer. If you have a very big file archive, and want to extract a small file, Zip allows you to do that. But with tar.gz, you need to extract entire archive.

1
  • Not an archive of gzipped files but a gzip of archived files. That's why you have to extract the whole archive.
    – csha
    Commented Feb 15, 2015 at 16:24
2

The decision basically comes down to these:

  • GZIP keeps Unix file permissions, as files being allowed to execute.

  • On the other hand ZIP works out of the box in Windows.

1

tar and gzip are a lot more common on *nix-es than unzip. For instance, at the moment on my arch-2009.08 there is no unzip.

1
  • 8
    But there is bsdtar (part of libarchive), which handles ZIP fine. Commented May 29, 2010 at 19:19
-1

I have experienced that there is concrete difference.

If you are compressing programs with libraries, zip format may lead to "file format not recognized" or "syntax error", because of the lack of information. Tar compression ensure to keep safe also all attribute.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .