Zip a Folder on Mac OSX Without the Pesky .DS_Store Files

| 4 Comments

Zip med UNIX kommandoer i Terminal på Mac OSXRecently, while trying to upload a zipped project to the WordPress Theme Directory, it was immediately rejected because it contained hidden files. More than once, I tried to create a new zip file, and although I had made sure to delete any hidden files, they kept showing up.

The Finder on the Mac creates hidden .DS_Store files which are used for keeping track on icons, folder backgrounds etc. These files can create trouble under certain circumstances as, for instance in the above mentioned situation. Also they may look a little suspicious to Windows users to whom the Mac user has tried to send a zipped archive.

(But hey! Please don’t make fun of my Mac: Windows also creates annoying hidden files, for instance Thumbs.db.)

The Command Line to the Rescue

I don’t particularly like the Termnial. The user interface is command based and reminds me a little too much of the old DOS-days. I’m much more of a GUI person.

But the terminal is a problem solver. It easily solves the trouble with the annoying .DS_Store files.

How To:

Firstly, navigate to the folder, in which the files you want to zip, are placed.
(Example: In the folder “foo” you have the folder “bar”, which you want to zip. Navigate to “foo”.)

cd [foo]

Now we’re going to zip the folder “bar”. Use the following command:

zip -r bar.zip bar -x "*.DS_Store"

Explanation:

  • -r recursively includes all directories underneath the targets we want to zip.
  • bar.zip is the name of the zip archive we are creating.
  • bar is the target directory we want to zip up.
  • -x "*.DS_Store" excludes all files whose path ends in the string “.DS_Store”.

Via

Author: Morten Brunbjerg Bech

Webdesigner, front end udvikler og bibliotekar. Arbejder primært med udvikling og design af Horsens Kommunes Bibliotekers webløsninger og er specialist i semantisk strukturering af webdokumenter samt Adobe Photoshop og Illustrator.

4 Comments

  1. When I use the terminal, it says ‘zip warning: name not matched; essenth (that’s the name of the folder I want to zip) and after the warning: ‘zip error: nothing to do! (essenth.zip)
    Do you have any idea what I’ve done wrong?

    • It may be because you are in the wrong directory. In terminal, try listing the contents of the current directory typing ‘ls’. If ‘essenth’ doesn’t appear in the list, you are in the wrong directory. Then you need to navigate to the right directory using the ‘cd’ command.

      Hope it helps.

  2. I’m not a big fan of copy-paste-codes-in-terminal. I found an app called “FolderWasher” to zip folders in Mac without .DS_Store files, but the app isn’t working? Have you ever tried this app? Does it not work with the latest OS X versions?

Leave a Reply