Site Navigation

Mar 27, 2008

Create a Clean Zip on OS X Leopard 10.5

Have you ever created a zip archive on your Mac and sent it to folks on another OS? Have they complained about about all the metadata directories included in the zip? An extra .DS_Store and __MACOSX directory, in every directory, seems to always cause a few complaints. What is a Mac fan boy/girl supposed to do?

Well last week I did a little searching around for a solution. I found several Applescript solutions that seemed a bit over complicated to me and require much more effort than I am willing to provide. :) There must be a simpler solution to the problem, and I think I have found it.

You can use the built in zip command to get a clean archive. I haven't thoroughly tested this, but so far it seems to work. To produce a clean metadata free archive use the following command:

zip -rX archive_name.zip dir_to_zip -x *.DS_Store*

A brief explanation is in order.

  • The -r switch recurses the target directory and gets all subdirectories.
  • The -X switch removes "extra file attributes" according to the man page. It seems to remove the "__MACOSX" files as well.
  • The -x switch allows you to provide a space separated list of file or directory patterns to exclude. So for example, if you needed to remove subversion directories you could add *.svn* to the end of the example.

I've tested the zips created with this method on XP and on Ubuntu 7.10 and both seem to be metadata free. Please drop me a comment if you can further elaborate or have a better version of this command. The best solution must be found for the sake of Mac users everywhere! :)

Post a Comment

Favorite Links Feed