I have a large number of zip files that were compressed using the zip command. I would like to recompress them with the -9 flag to improve the compression ratio. Does anyone know if that can be done without manually decompressing and then compressing.

PS. I need to keep them as zip files since they are served to windows users( and as such have white spaces in their names)

  • re-compression is only possible by decompressing the file and compressing again. it is algorithm dependent. You could also try bzip2 or even better xz.
    – user55518
    Feb 19, 2014 at 17:25
  • Tip: this can also be done with XLSX or XLSM Excel files since they're actually ZIP files containing XMLs and other stuff. Mar 17, 2018 at 22:02

2 Answers 2


You cannot improve the compression ratio, without decompressing the data. You don't have to extract all of the zip files before compressing them, but I would recommend uncompressing one whole zip file before re-compressing.

It is possible to recompress the files in a zip file one at a time and re-adding them before going to the next file contained in the zip file. This requires N rewrites of the zip file for a zip file containing N files. It is much more efficient to extract the N files and generate the new zipfile in one go, compressing all files with -9.

  • 1
    My goal is not to avoid decompression, rather to keep the archive structure the same. and not to change any file metadata.
    – Smartelf
    Feb 19, 2014 at 18:23
  • 1
    @Smartelf I don't think you can avoid decompression. Your other requirements are possible, there is no reason any data would have to change.
    – terdon
    Feb 19, 2014 at 18:26
  • 3
    @Smartelf as I already indicated, you **have to ** recompress. Assigning the same file metadata should not be a problem if you do this e.g. with a Python program and its zip module. With unzip/zip keeping the metadata the same is probably more difficult.
    – Anthon
    Feb 19, 2014 at 18:59

There is a utility called AdvanceCOMP that does exactly what you're looking for. It recompresses ZIP and GZ files (and some others) without intermediary extraction to disk. (I do believe that the mechanism used is to decompress the data and recompress it, but that does not require writing files to disk or regenerating metadata.)

You must log in to answer this question.

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