Zipping files on Mac without .DS_Store and __MACOSX

If you have ever compressed a folder on Mac and then opened it on another machine with a different operating system like Windows you have no doubt seen that there are 2 files you didn’t expect in the final folder. The .DS_Store and __MACOS files are used by MacOS, but don’t do anything on other OS’s. Thankfully the terminal comes to the rescue if you want to compress a folder without these being included you can use the following command

zip -r COMPRESSED_FILENAME.zip FOLDER_TO_COMPRESS -x ".DS_Store" -x "__MACOSX"

Although the Man for zip on MacOS will tell you

zip -r workfolder.zip work -x ".*" -x "__*"
This will ensure that no additional files are seen if the zip is extracted on a non-Apple PC.

There is a bit of a catch. If you do dev work and have files or folders like .htaccess those will get left out too which can be a potential issue. If you are not worried about these then use this. If you are like me and want to keep everything else expect those pesky two files use the first example!

Leave a Reply