Compress without .DS_Store and __MACOSX

You can use zip command in Terminal to zip the files without the .DS_Store, __MACOSX and other .* files.

  1. Open Terminal (search for terminal in spotlight)
  2. Navigate to the folder you want to zip using the cd command
  3. Paste this:
    zip -r . -x ".*" -x "__MACOSX"


Let's say you have a folder on your desktop called Folder with stuff to zip.
Open terminal and write following commands:

  1. cd Desktop/Folder
  2. zip -r . -x ".*" -x "__MACOSX"

Now you have a file called without __MACOSX and .* files in the folder Folder on your desktop.

Just some extra information ...

My understanding is that __MACOSX is a subdirectory artificially created by the Mac GUI tools to hold meta data such as extended attributes that can't be normally saved in a zip file.

If you use the Mac GUI tools to unpack the zip file, then the tools will know what to do with __MACOSX and the directory won't actually get unpacked.

The problems happen when you send your .zip file to Windows or Linux users, or just use the general-purpose unzip program to unpack them. Those tools won't know that __MACOSX is special, and will just unpack it.

The simplest option is to use zip to pack up your zip file instead of the Mac built-in tool. zip won't create __MACOSX and your problem is solved. (You will lose the meta data in the process, but you probably didn't want it anyway.)

zip -r dir

If it's too late, and you already have a zip file with __MACOSX, you can still remove it with:

zip -d __MACOSX .DS_Store

Finally, the accepted answer is the best because if for some reason __MACOSX actually does exist in your directory (e.g. because you previously used unzip to create it), the -x option will keep it from being packed up.

Try Keka. It comes with an option to exclude .DS_Store

enter image description here

Only one I've ever really used is BetterZip [$20]

It is a GUI app, but has Applescript & Services support, with which you can run presets with your default settings - including omitting Mac-specific files like .DS_Store & __MACOSX. Possibly worth a look.

From the BetterZip Help...

BetterZip supports two services: one for extracting and one for creating archives. You can configure what the BetterZip services will do with presets.

To use a service, select one or more files or folders in the Finder and choose Compress with BetterZip or Extract with BetterZip from the Finder > Services menu or the Services submenu in the contextual menu.

You can even set keyboard shortcuts for the BetterZip services, e.g., ^⌥⌘C for compressing and ^⌥⌘E for extracting. To set shortcuts for services, go to System Preferences > Keyboard > Keyboard Shortcuts and choose Services in the left table. In the right table, scroll to Files and Folders, choose Compress with BetterZip and press ↩. An editable textfield will appear. Press the desired shortcut.

One of my Save presets...

enter image description here

Based on itunes answer. I needed to also remove DS_Store in nested directories as follows.

zip -r . -x "**/.DS_Store"