When I compress a folder or file by right click menu of Mac OS X, the archived file contains .DS_Store and __MACOSX folders. Because I share the archived file online for download, Windows users mistakenly trying to search the file in __MACOSX folder.

I need to have a cleaner archive option. I do not want to include .DS_Store and __MACOSX folder, but only the file or folder into the archive file.

All I found is CleanArchiver but it is GUI application. It really takes time and I have lots of files to compress. I am looking for a solution by context menu if possible.

Is there any solution that you can recommend for clean compressing?

  • in my case I was packaging the files for use in Cloud Functions in GCP. The hidden files causes error
    – cryanbhu
    Apr 8, 2021 at 7:15

5 Answers 5


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 dir.zip . -x '**/.*' -x '**/__MACOSX'
    If you want to only filter .DS_Store files and keep other hidden files, use:
    zip -r dir.zip . -x '**/.DS_Store'


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 dir.zip . -x '.*' -x '__MACOSX'

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

  • 1
    +1 Can you wrap that into an automator service?
    – fd0
    May 25, 2016 at 18:00
  • 6
    Technically speaking, if you use zip to create the zip file, "__MACOSX/" won't get created in the first place, so all you really need is zip -r dir.zip .. However, if "__MACOSX/" somehow snuck in there, your solution will get rid of it. Jul 19, 2016 at 21:35
  • 5
    Also you can easily verify that your zip file does not have __MACOSX in it by typing in the console zipinfo dir.zip
    – Fostah
    Oct 24, 2016 at 21:45
  • 3
    This looks like it will exclude all files starting with a dot, not just .ds_store? Am I right? Nov 20, 2020 at 12:25
  • @somnolentsurfer That's correct.
    – iTunes
    Nov 20, 2020 at 12:56

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.zip dir

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

zip -d foo.zip __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.

  • 2
    .DS_Store is still created when using zip -r dir.zip . Sep 11, 2020 at 7:54
  • Yes, I find it annoying myself. This is similar to, but not the same as the stuff stored in __MACOSX Mar 19, 2021 at 21:11
  • 1
    Also see: stackoverflow.com/questions/10924236/…
    – GDP2
    Aug 17, 2021 at 23:32
  • zip -d foo.zip __MACOSX .DS_Store -> works Feb 11, 2022 at 11:32

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

enter image description here


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

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


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

  • That's a good GUI option for Setapp users.
    – Leo
    Jan 20, 2020 at 4:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .