86

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 isCleanArchiver 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?

askedMay 25, 2016 at 16:32
John Bernard's user avatar
1
  • in my case I was packaging the files for use in Cloud Functions in GCP. The hidden files causes errorCommentedApr 8, 2021 at 7:15

6 Answers6

120

You can usezip command inTerminal 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 thecd 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'

Example

Let's say you have a folder on your desktop calledFolder 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 calleddir.zip without__MACOSX and.* files in the folderFolder on your desktop.

answeredMay 25, 2016 at 17:53
iTunes's user avatar
5
  • 8
    Technically speaking, if you usezip to create the zip file, "__MACOSX/" won't get created in the first place, so all you really need iszip -r dir.zip .. However, if "__MACOSX/" somehow snuck in there, your solution will get rid of it.CommentedJul 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 consolezipinfo dir.zipCommentedOct 24, 2016 at 21:45
  • 6
    This looks like it will exclude all files starting with a dot, not just .ds_store? Am I right?CommentedNov 20, 2020 at 12:25
  • @somnolentsurfer That's correct.CommentedNov 20, 2020 at 12:56
  • Also see:stackoverflow.com/questions/10924236/…CommentedAug 17, 2021 at 23:32
29

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-purposeunzip program to unpack them. Those tools won't know that __MACOSX is special, and will just unpack it.

The simplest option is to usezip 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 usedunzip to create it), the -x option will keep it from being packed up.

answeredJul 19, 2016 at 21:33
Edward Falk's user avatar
4
  • 2
    .DS_Store is still created when using zip -r dir.zip .CommentedSep 11, 2020 at 7:54
  • Yes, I find it annoying myself. This is similar to, but not the same as the stuff stored in __MACOSXCommentedMar 19, 2021 at 21:11
  • 1
    Also see:stackoverflow.com/questions/10924236/…CommentedAug 17, 2021 at 23:32
  • zip -d foo.zip __MACOSX .DS_Store -> worksCommentedFeb 11, 2022 at 11:32
14

TryKeka. It comes with an option to exclude .DS_Store

enter image description here

answeredDec 15, 2016 at 7:34
ohho's user avatar
6

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

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

answeredMar 29, 2021 at 2:10
Ronald Petty's user avatar
4

Only one I've ever really used isBetterZip [$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

answeredMay 25, 2016 at 16:47
Tetsujin's user avatar
1
  • That's a good GUI option for Setapp users.CommentedJan 20, 2020 at 4:52
0

It sounds like you're in need of a solution to create ZIP files on macOS without including those pesky hidden files like .DS_Store and __MACOSX. I recommend using a script I developed called "Magic Mac Zipper." This script is designed to exclude all those unwanted hidden files automatically when creating your ZIP archive, making it perfect for clean distributions or submissions, such as WordPress plugin directories.

To use "Magic Mac Zipper," simply download the script, make it executable with chmod +x magic_mac_zipper, and run it from the terminal with your target directory as the argument. It streamlines the process and ensures your ZIP files are free from macOS-specific clutter.

Here the link:https://wpstar.it/wordpress-plugin-submission-magic-mac-zipper

answeredMar 11, 2024 at 10:22
Francesco Mincio's user avatar
1
  • Why not just create a tar file?CommentedMar 11, 2024 at 12:07

You mustlog in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.