How to Exclude Files in the Zip Archive Guide

This guide is about How to Exclude Files from a Zip Archive. I will do my best so that you understand this guide very well. I hope you all like this guide on How to Exclude Files from a Zip Archive.

The easiest way to unzip many individual files or a bunch of similar files from a zip archive is to skip the easy zip utility built into Mac OS X’s friendly interface and go to the command line where the t – powerful zip command installed.

This is useful for a million and one reasons, but the main motivation of this post is to send .DS_Store files with zip archives created on one Mac, only to decompress another machine, whether on another Mac, Windows PC, or Linux. This happens by default with the friendly zip tool and the command line zip utility, because the default function of the zip tools is to include hidden files, regardless of whether they are displayed. It’s not necessarily a bad thing, and in many cases it’s considered useful, but if you don’t want them or other relevant files to appear in your archive, read on.

Exclude files from the Zip archive

The basic information about excluding files when creating a zip archive is focused on the -x flag, which is used to exclude files from the archive that match a specific name or pattern. It is the most basic, it is like this:

zip archive.zip files -x “ExcludeMe”

This means you can exclude a single file by saying its name is “Nothanks.jpg”.

zip archive.zip images / -x “Nothanks.jpg”

Here are some specific examples if this is helpful.

Exclude .DS_Store files from Zip archives

This prevents normally invisible Mac metadata from being included in .DS_Store files in a bundled zip archive by default:

zip -r archivename.zip archive directory -x “*.DS_Store”

If the directory contains a subdirectory, however, you must use another command variant to close the ds_store files from the subdirectories as well:

zip -r archive.zip directory -x “* /. DS_ Shop”

Note: Not all scripts require quotation marks for this command to work correctly, but in the bash shell (default in Mac OS X), you must use quotation marks to enclose it with cards wild and patterns.

Exclude certain file types from the zip archive

Artificial cards also allow you to exclude all specific file types by targeting the extension. For example, this command compresses the entire directory minus all .jpg files:

zip -r archive.zip directory -x “*.jpg”

It can be modified with any specific file extension or template that matches the file name.

Exclude the .git or .svn directory from the zip archive

Zip directory minus .git and its contents: zip -r zipdir.zip directorytozip -x “* .git *”

Zip folder without .svn directory: zip -r zip.zip directory -x “* .svn *”

Close all hidden files in the zip archive

Because templates and wildcards can be used, you can also exclude all invisible files and folders added with a dot, whether it’s a directory like .svn or a single file like .bash_profile or .htaccess.

zip -r filename.zip driverozip -x “*. *”

Or leave out all invisible files in all subdirectories:

zip -r archive.zip directory -x “* /. *”

Kudos to the Macworld forum commenters for the exact syntax of excluding these files from subdirectories as well.

Zip archive icon

Ultimately, this is just one reason for power users to move to the terminal to create archives. Powerful features like wildcard support, exclusion, and optional password protection with zippers, it’s just more versatile, and since everything is included with the Mac anyway, you don’t need to download a new app to support the complex features.

And yes, technically, if you chose to stay in the UI, you can use the Finder and Spotlight search operators to narrow down the contents of a folder in Mac OS X before creating the archive, or just select all and manually Command + Click all those files including them, but it’s really not efficient in large archive operations. So, the terminal wins easily, and despite being command-line oriented, it’s not really complicated once you learn the basics.

Benefits: How to Exclude Files from a Zip Archive

  • The guide on How to Exclude Files from a Zip Archive is free to read.
  • We help many internet users to follow up interest in a convenient way.
  • The price of the How to Exclude Files from a Zip Archive guide is free.

FAQ: How to Exclude Files from a Zip Archive

In this guide, I told you about How to Exclude Files from a Zip Archive.

In this guide, I discuss about How to Exclude Files from Zip Archive, which is very helpful.

Apple devices only.

mac OS or iOS

Final note: How to Exclude Files from a Zip Archive

If you have any question regarding How to Exclude Files from Zip Archive, ask us through the comment section below or contact us directly.
Education: This guide or tutorial is for educational purposes only.
Misrepresentation: If you want to correct any incorrect information about the “How to Exclude Files from a Zip Archive” guide, kindly contact us.
Trying to add an alternate method: If anyone wants to add more methods to the How to Exclude Files from Zip Archive guide, kindly contact us.
Our Contact: Kindly use our contact page for any help.

Leave a Comment