Creating zip files from the “Compress” feature in OSX is nice and convenient, however you end up adding Mac hidden directories and files as well. Normally this would include things like .DS_Store and .svn if you are using version control.

It is possible to exclude these files without buying an application to do it and this technique can be extended to exclude other files and directories as needed. Whether you are familiar with the “Terminal” or not, you should find it quite easy to implement and we can make use of the exclude directive (-x) to do away with these annoyances.

To start the “Terminal” just hit the [Command+Spacebar], without the square brackets, and type “terminal”. To navigate around type something like “cd /Applications/XAMPP/htdocs”. [cd] means ‘Change directory’.

The exclude directive (-x) has a unique feature that allows you to include a file that contains all your arguments along with any desired patterns, which trust me simplifies the process.

So, lets see how to do this…

$> zip -vr myArchive.zip * -x@ excluded.lst

Let’s break that down a bit. [zip] is the name of the tool. [-vr] v is for verbose and r is for recursive into directories. [myArchive.zip] is the zip archive we want to fill with the files/folders. [*] means all files in the current directory. [-x] means exclude the following files and directories. [excluded.lst] is the file we create and put our patterns in. [-x@excluded.lst] is the full command for excluding files, the lack of spaces between things is important, so don’t put any in.

The excluded.lst should look like the following to start with, just create it using a text editor and save it in the same directory where you are running the terminal command above. This way you can just copy-paste it to the next potential archiveable directory.

Add the following to a file named excluded.lst

$> *.svn* *.DS_Store* excluded.lst

The [*] means everything before or everything after that matches. We have exclude.lst as a specific file name to exclude the pattern file.

Hope this helps someone out there.