When ZIP up directories, particularly on macOS, some files may find their way into our ZIP archives that were never meant to be there. I’m thinking of those pesky .DS_Store and __MACOSX files, maybe even .htaccess files. For *nix based systems, * really means “everything”.
The ZIP command line tool let us remove such unwanted files from an existing archive. Here’s how:
zip -d your-archive.zip file1 file2
The -d switch tells ZIP to hunt for and delete the unwanted files. Files whose names contain spaces can be defined in “regular quotes”, and the * asterisk can be used as usual.
For example, to remove all DS_Store files and __MACOSX files, we can use this:
zip -d your-archive.zip "__MACOSX*" DS_Store*
To verify that such idiosyncrasies have indeed been removed from a ZIP archive before we release it into the wide, we can check with the UNZIP utility:
unzip -l your-archive.zip
This will simply list the contents of your-archive.zip without actually extracting it.