ywat ywat - 3 months ago 48
Linux Question

Linux command to edit zip file generated from numpy savez function

I want to edit zip file generated by numpy savez function. For example we can make a zip file like

>>> import numpy as np
>>> x = np.array([1,2,3])
>>> y = np.array([4,5,6])
>>> dat = {'/path/to/x': x, '/path/to/y': y}
>>> f = open('foo', 'wb')
>>> np.savez(f, **dat)

This code creates a zip file named foo. (On ubuntu GUI, it is shown as Zip archive type)

Then, I want to remove the file y in the zip file. (Without using Python)

I have tried an approach that first unzip the file and manually remove the file and zip it again. I made a zip file by
command, but it generates gzip-compressed tar archive.

What is the correct way to edit and generate zip file generated by numpy save_z?


Use the -d option from the zip command like this:

zip foo -d y

This will delete file y from the zip file foo.

You can check the files stored in the zip file with unzip -l foo to check the full path and names of the files stored in foo.