Zip a folder on a Mac without __MACOSX and .DS_Store
Send a ZIP made with Finder’s Compress to someone on Windows or Linux, and they’ll often find extra items inside:
- A
__MACOSXfolder full of files starting with._. These hold Mac-only information (extended attributes such as where a file was downloaded from). macOS merges them back into the files when it expands the ZIP; other systems show them as files. .DS_Storefiles, which store Finder’s view settings for a folder. They’re ordinary hidden files in the folder, so they get zipped along with everything else.
Neither does any harm, but they’re clutter, and on a shared or public ZIP
they look careless. A .DS_Store can also contain the names of files that
used to be in the folder, which you may not mean to share.
1. Terminal: zip (free)
The zip command doesn’t create __MACOSX at all, and -x leaves out the
.DS_Store files:
cd ~/Desktop
zip -r -X Clean.zip "My Folder" -x "*.DS_Store"-X also leaves out extra Unix file attributes that other systems don’t
need.
2. Clean up a ZIP you already made (free)
zip -d Archive.zip "__MACOSX/*" "*.DS_Store"That deletes both from the existing ZIP, in place. If there’s nothing to
remove, zip says “Nothing to do!”, which is harmless.
3. Purrchiver
Purrchiver doesn’t add a __MACOSX folder or ._ files when it makes a
ZIP. Its Strip macOS metadata option (on by default in the Create sheet)
also leaves out any that are already in what you’re zipping, such as from a
ZIP you expanded earlier. .DS_Store files are ordinary files in your
folder, so Purrchiver includes them like anything else; delete them first,
or use the zip commands above, if you don’t want them. Creating ZIPs is
free.
To check a ZIP before sending it, list what’s inside:
unzip -l Archive.zipWhat about ditto?
ditto -c -k --norsrc --keepParent "My Folder" Out.zip skips __MACOSX
too, but it still includes .DS_Store.