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?

up vote 17 down vote accepted

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

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

Example: Let's say you have a folder on your desktop called Folder with stuff to zip.
Open terminal and write following commands:
cd Desktop/Folder
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 '16 at 18:00
  • 2
    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. – Edward Falk Jul 19 '16 at 21:35
  • 1
    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 '16 at 21:45

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 .

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.

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

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.