How to Exclude Files in a Zip Archive

Learn how to exclude specific files when creating a zip archive with these easy-to-follow steps.

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

The easiest way to close many specific files or a bunch of similar files from a zip archive is to skip the easy zip utility built into the friendly interface of Mac OS X and go to the command line where the powerful zip command is located.

This is useful for a million and one reasons, but the primary motivation for this post is related to .DS_Store files shipped with zip archives created on one Mac, only to shuffle another machine that decompresses the file, whether on another Mac, Windows PC, or Linux . This happens by default with both the friendly zip tool and the command line zip utility, and is because the default function of 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, then read on.

Exclude files from the Zip archive

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

zip archive.zip files -x “ExcludeMe”

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

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

Here are a few specific examples if this is helpful.

Exclude .DS_Store files from Zip archives

This prevents typically invisible Mac metadata from including .DS_Store files in bundled zip archives by default:

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

However, if the directory contains subdirectories, you must use another command variant to also close the ds_store files from the subdirectories:

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

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

Exclude certain file types from the zip archive

Wildcards also allow you to exclude all specific types of files by focusing on 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 to any specific file extension or template that is matched to 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 or all invisible files and folders that have been 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 exclude all invisible files in all subdirectories:

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

Cheers to 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 have to download a new app to support the advanced features.

And yes, technically, if you chose to stay in the UI, you can use the Finder and Spotlight search operators to narrow the contents of folders in Mac OS X before creating the archive, or just select all and manually Command + Click each file without including them, but it’s really not effective in large archiving operations. Thus, the terminal wins easily, and despite being focused on the command line, it really isn’t complicated once you learn the basics.

Benefits: How to Exclude Files from a Zip Archive

[wpsm_list type=”star”]

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

[/wpsm_list]

FAQ: How to Exclude Files from a Zip Archive

[wpsm_accordion]
[wpsm_accordion_section title=”Guide about How to Exclude Files from a Zip Archive”]
In this guide, I told you about the How to Exclude Files from a Zip Archive.
[/wpsm_accordion_section]
[wpsm_accordion_section title=”How this Guide helping you?”]
In this guide, I discuss about the How to Exclude Files from a Zip Archive, which is very helpful.
[/wpsm_accordion_section]
[wpsm_accordion_section title=”What are the supported devices for this guide?”]
Apple Devices only.
[/wpsm_accordion_section]
[wpsm_accordion_section title=”What are the supported Operating system?”]
mac OS or iOS
[/wpsm_accordion_section]
[/wpsm_accordion]
[wpsm_divider top=”2px” bottom=”15px” style=”fadeout”]

Final note: How to Exclude Files from a Zip Archive

If you have any queries regards the How to Exclude Files from a Zip Archive, then please ask us through the comment section below or directly contact us.
Education: This guide or tutorial is just for educational purposes.
Misinformation: If you want to correct any misinformation about the guide “How to Exclude Files from a Zip Archive”, then kindly contact us.
Want to add an alternate method: If anyone wants to add more methods to the guide How to Exclude Files from a Zip Archive, then kindly contact us.
Our Contact: Kindly use our contact page regards any help.

Editorial Staff
Editorial Staffhttps://www.bollyinside.com
The Bollyinside editorial staff is made up of tech experts with more than 10 years of experience Led by Sumit Chauhan. We started in 2014 and now Bollyinside is a leading tech resource, offering everything from product reviews and tech guides to marketing tips. Think of us as your go-to tech encyclopedia!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related Articles

Best Telemedicine Software: for your healthcare practice

Telemedicine software has transformed my healthcare visits. It's fantastic for patients and doctors since they can obtain aid quickly. I...
Read more
I love microlearning Platforms in today's fast-paced world. Short, focused teachings that engage me are key. Microlearning platforms are great...
Think of a notebook on your computer or tablet that can be changed to fit whatever you want to write...
As of late, Homeschool Apps has gained a lot of popularity, which means that an increasing number of...
From what I've seen, HelpDesk software is essential for modern businesses to run easily. It's especially useful for improving customer...
For all of our important pictures, stories, and drawings, Google Drive is like a big toy box. But sometimes the...