When I compress files with the built in zip compressor in Mac OSX, it causes an extra folder titled "__MACOSX" to be created in the extracted zip.
Can I adjust my settings to keep this folder from being created or do I need to purchase a third party compression tool?
UPDATE: I just found a freeware app for OSX that solves my problem: "YemuZip"
UPDATE 2: YemuZip is no longer freeware.
- The existence of _MACOSX folder doesn't creates any problem. Simply delete it.Jayprakash Dubey– Jayprakash Dubey2014-03-14 06:04:18 +00:00CommentedMar 14, 2014 at 6:04
- 3This question appears to be off-topic because it should be in AskDifferentNakilon– Nakilon2015-01-12 02:48:08 +00:00CommentedJan 12, 2015 at 2:48
- 30It creates a problem with picky web services that require a pristine zip archive, so I'm grateful for the explanationsmccc– mccc2015-11-19 18:15:11 +00:00CommentedNov 19, 2015 at 18:15
- 43@JayprakashDubey It's incredibily irritating, and as a linux user who likes not leaving trash everywhere I go, I can't stand
__MACOSX,.DS_Store,._fileName, and all the other assorted turds Mac OS drops in its archives. OSX's `tar' does this as well - in blatant disregard for theprinciple of least astonishment.Wyatt Ward– Wyatt Ward2016-06-28 18:13:46 +00:00CommentedJun 28, 2016 at 18:13 - Also see:apple.stackexchange.com/questions/239578/…GDP2– GDP22021-08-17 23:32:56 +00:00CommentedAug 17, 2021 at 23:32
16 Answers16
Can be fixed after the fact byzip -d filename.zip __MACOSX/\*
And, to also delete.DS_Store files:zip -d filename.zip \*/.DS_Store
9 Comments
zip -d filename.zip \*/.DS_Storefind ~ -type f -name '*.zip' -exec zip -d '{}' __MACOSX/\* \;. Substitute your starting point for~.cleanzip(){ zip -d $1 $2 __MACOSX/\* \*/.DS_Store; }. Usage:cleanzip file.zip orcleanzip file.zip MORE_JUNK_FILES (second parameter is optional)When I had this problem I've done it from command line:
zip file.zip uncompressedEDIT, after many downvotes: I was using this option for some time ago and I don't know where I learnt it, so I can't give you a better explanation. Chris Johnson'sanswer is correct, but I won't delete mine. As one comment says, it's more accurate to what OP is asking, as it compress without those files, instead of removing them from a compressed file. I find it easier to remember, too.
5 Comments
zip, which is a 3rd-party app, then the __MACOSX/ directory never gets created in the first place.zip -rX file.zip uncompressed_directoryInside the folder you want to be compressed, in terminal:
zip -r -X Archive.zip *Where -X means: Exclude those invisible Mac resource files such as “_MACOSX” or “._Filename” and .ds store files
Note as per comment by@SpinUp__ADavis: Will only work for the folder and subsequent folder tree you are in and has to have the* wildcard.
6 Comments
-X does not exclude .DS_Store files. The reason it may work for your application is that you're only zipping*, which is a wildcard matching files that don't begin with ".". Try it on a directory containing a dot-file, and you'll see it gets included.zip -r -X Archive.zip myfolder on a folder still results in a zip file containing .DS_Store file.This command did it for me:
zip -r Target.zip Source -x "*.DS_Store"Target.zip is the zip file to create.Source is the source file/folder to zip up. The-x parameter specifies the file/folder to exclude.
If the above doesn't work for whatever reason, try this instead:
zip -r Target.zip Source -x "*.DS_Store" -x "__MACOSX"2 Comments
zip command line utility never creates a__MACOSX directory, so the first snippet does work, and the-x "__MACOSX" part is not needed.I'm using this Automator Shell Script to fix it after.It's showing up as contextual menu item (right clicking on any file showing up in Finder).
while read -r p; do zip -d "$p" __MACOSX/\* || true zip -d "$p" \*/.DS_Store || truedone- Create a new Service with Automator
- Select "Files and Folders" in "Finder"
- Add a "Shell Script Action"
5 Comments
zip -d "$p" __MACOSX/\* || true into your answer.zip -r "$destFileName.zip" "$srcFileName" -x "*/\__MACOSX" -x "*/\.*"-x "*/\__MACOSX": ignore __MACOSX as you mention.-x "*/\.*": ignore any hidden file, such as .DS_Store .- Quote the variable to avoid file if it's named with SPACE.
Also, you can build Automator Service to make it easily to use in Finder.Check link below to see detail if you need.
2 Comments
The unwanted folders can be also be deleted by the following way:
zip -d filename.zip "__MACOSX*"Works best for me
Comments
Cleanup .zip from.DS_Store and__MACOSX, including subfolders:
zip -d archive.zip '__MACOSX/*' '*/__MACOSX/*' .DS_Store '*/.DS_Store'Walkthrough:
- Create .zip as usual by right-clicking on the file (or folder) and selecting "Compress ..."
- Open Terminal app (search Terminal in Spotlight search)
- Type
zipin the Terminal (but don't hit enter) - Drag .zip to the Terminal so it converts to the path
- Copy paste
-d '__MACOSX/*' '*/__MACOSX/*' .DS_Store '*/.DS_Store' - Hit enter. Congratulations! Your archive is sparkling clean!
- Use
zipinfo archive.zipto list files inside to check (optional)
Comments
You can't.
But what you can do is delete those unwanted folders after zipping. Command linezip takes different arguments where one, the-d, is for deleting contents based on a regex. So you can use it like this:
zip -d filename.zip __MACOSX/\*Comments
Thezip command line utility never creates a__MACOSX directory, so you can just run a command like this:
zip directory.zip -x \*.DS_Store -r directoryIn the output below,a.zip which I created with thezip command line utility does not contain a__MACOSX directory, buta 2.zip which I created from Finder does.
$ touch a$ xattr -w somekey somevalue a$ zip a.zip a adding: a (stored 0%)$ unzip -l a.zipArchive: a.zip Length Date Time Name -------- ---- ---- ---- 0 01-02-16 20:29 a -------- ------- 0 1 file$ unzip -l a\ 2.zip # I created `a 2.zip` from Finder before thisArchive: a 2.zip Length Date Time Name -------- ---- ---- ---- 0 01-02-16 20:29 a 0 01-02-16 20:31 __MACOSX/ 149 01-02-16 20:29 __MACOSX/._a -------- ------- 149 3 files-x .DS_Store does not exclude.DS_Store files inside directories but-x \*.DS_Store does.
The top level file of a zip archive with multiple files should usually be a single directory, because if it is not, some unarchiving utilites (likeunzip and7z, but not Archive Utility, The Unarchiver,unar, ordtrx) do not create a containing directory for the files when the archive is extracted, which often makes the files difficult to find, and if multiple archives like that are extracted at the same time, it can be difficult to tell which files belong to which archive.
Archive Utility only creates a__MACOSX directory when you create an archive where at least one file contains metadata such as extended attributes, file flags, or a resource fork. The__MACOSX directory contains AppleDouble files whose filename starts with._ that are used to store OS X-specific metadata. Thezip command line utility discards metadata such as extended attributes, file flags, and resource forks, which also means that metadata such as tags is lost, and that aliases stop working, because the information in an alias file is stored in a resource fork.
Normally you can just discard the OS X-specific metadata, but to see what metadata files contain, you can usexattr -l.xattr also includes resource forks and file flags, because even though they are not actually stored as extended attributes, they can be accessed through the extended attributes interface. Both Archive Utility and thezip command line utility discard ACLs.
3 Comments
I have a better solution after read all of the existed answers. Everything could done by a workflow in a single right click.NO additional software,NO complicated command line stuffs andNO shell tricks.
The automator workflow:
Input: files or folders from any application.
Step 1: Create Archive, the system builtin with default parameters.
Step 2: Run Shell command, with input as parameters. Copy command below.
zip -d "$@" "__MACOSX/*" || truezip -d "$@" "*/.DS_Store" || true
Save it and we are done! Just right click folder or bulk of files and choose workflow from services menu. Archive with no metadata will be created alongside.
IMAGE UPDATE: I chose "Quick Action" when creating a new workflow - here’s an English version of the screenshot:
5 Comments
do not zip any hidden file:
zip newzipname filename.any -x "\.*"with this question, it should be like:
zip newzipname filename.any -x "\__MACOSX"It must be said, though, zip command runs in terminal just compressing the file, it does not compress any others. So do this the result is the same:
zip newzipname filename.anyKeka does this. Just drag your directory over the app screen.
1 Comment
Do you mean thezip command-line tool or the Finder's Compress command?
Forzip, you can try the--data-fork option. If that doesn't do it, you might try--no-extra, although that seems to ignore other file metadata that might be valuable, like uid/gid and file times.
For the Finder's Compress command, I don't believe there are any options to control its behavior. It's for the simple case.
The other tool, and maybe the one that the Finder actually uses under the hood, isditto. With the-c -k options, it creates zip archives. With this tool, you can experiment with--norsrc,--noextattr,--noqtn,--noacl and/or simply leave off the--sequesterRsrc option (which, according to the man page, may be responsible for the__MACOSX subdirectory). Although, perhaps the absence of--sequesterRsrc simply means to use AppleDouble format, which would create ._ files all over the place instead of one__MACOSX directory.
1 Comment
This is how i avoid the__MACOSX directory when compress files withtar command:
$ cd dir-you-want-to-archive$ find . | xargs xattr -l # <- list all files with special xattr attributes..../conf/clamav: com.apple.quarantine: 0083;5a9018b1;Safari;9DCAFF33-C7F5-4848-9A87-5E061E5E2D55./conf/global: com.apple.quarantine: 0083;5a9018b1;Safari;9DCAFF33-C7F5-4848-9A87-5E061E5E2D55./conf/web_server: com.apple.quarantine: 0083;5a9018b1;Safari;9DCAFF33-C7F5-4848-9A87-5E061E5E2D55
Delete the attribute first:
find . | xargs xattr -d com.apple.quarantine
Runfind . | xargs xattr -l again, make sure no any file has the xattr attribute. then you're good to go:
tar cjvf file.tar.bz2 dir
Comments
Another shell script that could be used with the Automator tool (see also benedikt's answer on how to create the script) is:
while read -r f; do d="$(dirname "$f")" n="$(basename "$f")" cd "$d" zip "$n.zip" -x \*.DS_Store -r "$n"doneThe difference here is that this code directly compresses selected folders without macOS specific files (and not first compressing and afterwards deleting).
Comments
Explore related questions
See similar questions with these tags.






















