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?
- in my case I was packaging the files for use in Cloud Functions in GCP. The hidden files causes errorcryanbhu– cryanbhu2021-04-08 07:15:10 +00:00CommentedApr 8, 2021 at 7:15
6 Answers6
You can usezip command inTerminal 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
cdcommand - Paste this:
If you want to only filter .DS_Store files and keep other hidden files, use:zip -r dir.zip . -x '**/.*' -x '**/__MACOSX'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:
cd Desktop/Folderzip -r dir.zip . -x '.*' -x '__MACOSX'
Now you have a file calleddir.zip without__MACOSX and.* files in the folderFolder on your desktop.
- 8Technically speaking, if you use
zipto 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.Edward Falk– Edward Falk2016-07-19 21:35:28 +00:00CommentedJul 19, 2016 at 21:35 - 5Also you can easily verify that your zip file does not have __MACOSX in it by typing in the console
zipinfo dir.zipFostah– Fostah2016-10-24 21:45:04 +00:00CommentedOct 24, 2016 at 21:45 - 6This looks like it will exclude all files starting with a dot, not just .ds_store? Am I right?somnolentsurfer– somnolentsurfer2020-11-20 12:25:14 +00:00CommentedNov 20, 2020 at 12:25
- @somnolentsurfer That's correct.iTunes– iTunes2020-11-20 12:56:15 +00:00CommentedNov 20, 2020 at 12:56
- Also see:stackoverflow.com/questions/10924236/…GDP2– GDP22021-08-17 23:32:17 +00:00CommentedAug 17, 2021 at 23:32
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 dirIf 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_StoreFinally, 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.
- 2.DS_Store is still created when using zip -r dir.zip .Steve Moretz– Steve Moretz2020-09-11 07:54:24 +00:00CommentedSep 11, 2020 at 7:54
- Yes, I find it annoying myself. This is similar to, but not the same as the stuff stored in __MACOSXEdward Falk– Edward Falk2021-03-19 21:11:43 +00:00CommentedMar 19, 2021 at 21:11
- 1Also see:stackoverflow.com/questions/10924236/…GDP2– GDP22021-08-17 23:32:08 +00:00CommentedAug 17, 2021 at 23:32
- zip -d foo.zip __MACOSX .DS_Store -> worksShubham Jain– Shubham Jain2022-02-11 11:32:28 +00:00CommentedFeb 11, 2022 at 11:32
TryKeka. It comes with an option to exclude .DS_Store
Based onitunes 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 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...
- That's a good GUI option for Setapp users.Leo– Leo2020-01-20 04:52:22 +00:00CommentedJan 20, 2020 at 4:52
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
You mustlog in to answer this question.
Explore related questions
See similar questions with these tags.





