How to create a zip file compatible with Windows under Linux

91,697

Solution 1

Try with:

zip -9 -y -r -q file.zip folder/
  • -9 Indicates the slowest compression speed (optimal compression, ignores the suffix list)
  • -y Store symbolic links as such in the zip archive, instead of compressing and storing the file referred to by the link
  • -r Travel the directory structure recursively
  • -q Quiet mode

Solution 2

7zip is an open source compression tool that works on Linux, FreeBSD, Mac OS X, BeOS, DOS, Amiga and Windows.

I would highly recommend it based on the windows version.

It supports

packing / unpacking: 7z, ZIP, GZIP, BZIP2 and TAR

Unpacking only: ARJ, CAB, CHM, CPIO, DEB, DMG, HFS, ISO, LZH, LZMA, MSI, NSIS, RAR, RPM, UDF, WIM, XAR and Z.

Solution 3

zip -Z sets the compression option. -Z store is the most trivial one, as it doesn't compress at all. This is useful when you're using zip as an alternative for tar, or when troubleshooting. In this case you should try to see if an uncompressed archive is usable from Windows. If that is usable, you know that you'll have to pick a non-default compression option.

Solution 4

Only thing that looks relevant is this

-k - Attempt  to  convert  the  names  and paths to conform to MSDOS, store only the MSDOS attribute (just the user write attribute from UNIX), and mark the entry as made under
MSDOS (even though it was not); for compatibility with PKUNZIP under MSDOS which cannot handle certain names such as those with two dots.

but do read "man zip" on your system before going anywhere else...

Solution 5

In addition to what others suggested, it's important pay Attention to your file and directory names as Windows does not necessarily like Linux file path and names. It sometimes also escapes them differently when zipping. Examples are numerous, but most importantly dot files (. and ..), files with only case differences (name.txt and NAME.txt), absolute file paths (/tmp/file.txt). Some other characters which are allowed in file names on Windows could cause issues when Windows Explorer is used to open files. In my case ':' character was the deal breaker but took a lot of work to find this out.

So before you resume to using using a lot of parameters, I suggest follow a simple procedure:

  1. Locate the folder or file your zipping up.

  2. run: zip -9 -r -k zip-modified-names.zip /path/to/your/folder

  3. pay attention to what the console spits out. In my case ':' in file names were stripped out.
  4. Move the zip file to a windows machine and attempt to open it.

If this works, you may be better off removing the characters that have been stripped off by -k option from your file/directory names try zipping normally. Note some parameters such as -k have side effects. In this case -k contradicts with -q option (for sym links).

Also -k option may render your file names unreadable. In my case my files were named based on creation time (e.g. 10:55:39.pdf) to facilitate easily locating the required record from archives, but -k option turned it to 105539.pdf which is not easily readable by users. I hence changed the names to 10_55_39.pdf which opens on Windows without using -k option but is still readable.

Share:
91,697

Related videos on Youtube

Admin
Author by

Admin

Updated on September 17, 2022

Comments

  • Admin
    Admin over 1 year

    I need to make a zip file available to all my Windows users visitors, so I naively produced a zip file with the Unix zip command (let's call it madeinlinux.zip).

    It opens successfully with WinRar or Winzip, but those of my users who are using the standard Windows zip file handling experience failure when trying to unzip it. (Windows XP)

    I compressed the same data using Windows built-in zip mecanism, and from a Linux point of view, I cannot see any difference in the file type:

    $ file madeinlinux.zip :  Zip archive data, at least v2.0 to extract
    $ file madeinwindows.zip : Zip archive data, at least v2.0 to extract
    

    They're must be something specific to a Windows compatible zip file.

    Does anyone knows what?

    • Bernhard Hofmann
      Bernhard Hofmann almost 15 years
      Could you produce one of these ZIP files (with dummy content) and put it on a server for us to download and inspect?
    • Admin
      Admin almost 15 years
      This sounds like a case for superuser.com, if it exists yet.
    • Admin
      Admin almost 15 years
      Sure bernhard, here's the culprit: careerjet.co.uk/devel/Services_Careerjet.zip
    • Admin
      Admin almost 15 years
      The only windows machine I had to test was a Windows 7 one, and that had no problems opening and extracting the file using explorer.
    • Admin
      Admin almost 15 years
      hail windows 7 !
    • Admin
      Admin almost 15 years
      use gzip. afaik .. it has no problem with windows extractor.
    • Hi-Angel
      Hi-Angel over 8 years
      I end up using format different from zip (like 7zip, rar, etc) — so that users wouldn't try opening that with the buggy built-in unzip.
  • Impression
    Impression almost 15 years
    Hi. Thx for the suggestion, but this -k option takes me back in time a bit too much. It transforms all file name in a 8 character/no case version :(
  • Admin
    Admin almost 15 years
    the question is, can it be unzipped using Windows zip mechanism?
  • Admin
    Admin almost 15 years
    yes. i've opened it with the Vista zip tool. I hope it works for you too
  • Impression
    Impression almost 15 years
    Yeah, I remember those days. But did it help the file to read by the built-in Zip program on Windows?
  • Adrien
    Adrien almost 15 years
    awesome, I'd guess it's the compression algorithm that is causing trouble too...
  • Impression
    Impression almost 15 years
    Don't know. This file name issue stopped me trying
  • Impression
    Impression almost 15 years
    My guess is that it's the compression, as MSalters says...
  • EKW
    EKW about 11 years
    According to the App. Notes on the pkware site ( pkware.com/support/zip-app-note/archives ): "The name of the file, with optional relative path. The path stored should not contain a drive or device letter, or a leading slash."
  • Hi-Angel
    Hi-Angel over 8 years
    @TD.512 have you noticed that the 6 years old question still doesn't have definite answer? Best to add another answer, if the answer seems to help someone as others didn't.
  • Rick O'Shea
    Rick O'Shea about 7 years
    I recommend not using yet another 3rd party proprietary tool for this unbelievably common utility (zip a file) available now on all platforms.
  • Wowfunhappy
    Wowfunhappy almost 5 years
    Why would this help with XP compatibility?
  • Wowfunhappy
    Wowfunhappy almost 5 years
    Disagree. I've run into similar problems as the OP, particularly with old versions of Windows. I've done integrity checks and the shasum's match up. Plus, note that OP says the files decompress properly in 3rd party programs.
  • Dr Fabio Gori
    Dr Fabio Gori almost 5 years
    Honestly it was so much time ago that I don't remember clearly; but I can imagine that following the symbolic links could lead to problems (that could happen without -r) and -r allows you take all the folder content
  • FiddlingAway
    FiddlingAway over 3 years
    @Wowfunhappy I can confirm that files zipped in this manner can be extracted with the default zip extractor in Windows XP SP3 (tested within a virtual machine).