Search code examples
macosterminalzip

Mac terminal zip: Size limit parameter does not work properly


I need to compress a huge folder into multiple zip files, but each of them should not exceed the size of 1 gigabyte.

I found the following command

zip -r -s 1g MyZipFile.zip folderToCompress/

But the resulted files do exceed the size of 1 gb:

-rw-r--r--  1 user  staff  1073741824 14 Feb 15:40 MyZipFile.z01
-rw-r--r--  1 user  staff  1073741824 14 Feb 15:42 MyZipFile.z02
-rw-r--r--  1 user  staff  1073741824 14 Feb 15:41 MyZipFile.z03
-rw-r--r--  1 user  staff  1073741824 14 Feb 15:42 MyZipFile.z04
-rw-r--r--  1 user  staff  1073741824 14 Feb 15:43 MyZipFile.z05
-rw-r--r--  1 user  staff  1073741824 14 Feb 15:43 MyZipFile.z06
-rw-r--r--  1 user  staff   865071084 14 Feb 15:44 MyZipFile.zip

What am I doing wrong?


Solution

  • zip appears to be limiting the size to 1 Gibibyte, not 1 Gigabyte when you specify the -s 1g argument.

    1GiB = 2^30 = 1073741824 bytes, which is why you're seeing that number instead of 1GB = 10^9 = 1000000000 bytes. I got the same result trying to zip a multi-GB folder on my own macOS High Sierra desktop. macOS since Snow Leopard handles file sizes according to standard Gigabytes, so it must be zip that is operating using Gibibytes instead. The zip man page states that you can only specify an argument for -s in KiB, MiB, GiB, or TiB.

    So, if you want exactly 1GB to be the size limit, you'd have to find some way to specify a size in KiB, MiB, GiB, or TiB which corresponds to 1000000000 bytes. I don't think that's possible; using a MiB to GB converter, the closest I could get to 1GB was 953.67431 MiB, and zip doesn't allow you to specify an -s argument that isn't a whole number.