Macos – Recursively compress files in a directory and subdirectories using command line “zip” tool in Mac OS X and exclude .DS_Store files from ALL subfolders

bsdcommand linecompressionmacoszip

I'm trying to create a ZIP file using the command line zip tool that comes with the Mac OS X Terminal. I want to recursively compress the contents of the current folder but excluding .DS_Store files. I'm trying with this:

zip -r myarchive.zip . -x .DS_Store

The -x .DS_Store excludes the .DS_Store file in the current folder, but not in the recursively added subfolders. How do I exclude all the .DS_Store files from ALL subfolders as well?

Best Answer

Add a wildcard to the exclude option

zip -r myarchive.zip . -x "*.DS_Store"
Related Question