How to remove files from ZIP Archives in macOS and Linux

- by

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 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 "__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

This will simply list the contents of without actually extracting it.

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site witout any pesky ads! More details here.

Add your voice!

This site uses Akismet to reduce spam. Learn how your comment data is processed.