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.
- 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.
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.
Try Keka. It comes with an option to exclude .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...
Based on itunes answer. I needed to also remove DS_Store in nested directories as follows.
zip -r my.zip . -x "**/.DS_Store"