Whenever we’re working on a project that requires some custom functionality, we still try to abide by the whole themes-are-for-presentation and plugins-are-for-functionality even if it’s not something that has any use outside of our projects.
This doesn’t mean we don’t use source control or anything like that, but it’s just that not everything that is open-source by its license is available for download because it has no applicability outside of a niche use case.
But that’s a discussion for another time.
All I’m saying is that even though we may be working on something just for us, we don’t abandon good development practices.
And there are times, say, where we may be sharing files, source code, or something via Slack that is not yet ready to either commit or to share any other way. In times like that, it’s helpful to be able to create a zip file, right?
But sometimes, we need to create a zip file with excluded files.
Creating a Zip File With Excluded Files
When it comes to excluding files, I’d venture to say that most of us are used to simply throwing rules into a gitignore file or something similar depending on your choice of source control system.
There are times, though, where you might want to create a simple zip file and exclude files from the archive. And if you’re on macOS this is how to do it:
zip -r name-of-file-to-create.zip directory-name -x "file-name" -x "directory-name"
-rwill iterate through the directory you’ve specified. This tells the program to include all of the files it finds.
- The second argument just specifies what you want to name the file.
- The third argument is specifies the actual directory to compress. So if you want to zip
/pluginthen you’ll want to be in its parent directory when issuing this command.
- The final arguments are what to exclude so
-x "file-name"will exclude the specified file or the specified directory.
You can read more about this in the zip man page.
Regardless, if you find yourself in a situation where you have, say, a WordPress plugin that you want to send someone, you don’t have it committed just yet, and you want to exclude, say, the
vendor directory, then this is one way to go about excluding it for them.