The zip command in macOS is an integral part of the terminal, enabling users to create (compress) and extract (decompress) ZIP archives, the most common file compression format. If you're new to macOS or just starting with the terminal, this guide will walk you through using the zip command like a pro.
Before we dive into the details, ensure you're comfortable with the macOS terminal. If not, you can open it via Spotlight Search (cmd + space) by searching for 'Terminal', or find it in Applications > Utilities.
Creating ZIP Archives with the zip command
Creating a ZIP archive, or compressing files, is useful for saving storage space and bundling multiple files together. Here's how you can do it using the zip command.
Creating a single-file ZIP archive
To create a ZIP archive from a single file, use the following syntax:
zip filename.zip file.ext
Creating a multi-file ZIP archive
You can also create a ZIP archive containing multiple files using a wildcard (*). Here's how:
zip filename.zip *
This command will create a ZIP archive named 'filename.zip' containing all files in the current directory.
Extracting Files from ZIP Archives with the unzip command
The unzip command is used to extract files from ZIP archives. It's an essential skill to have when working with compressed files.
Extracting all files from a ZIP archive
To extract all files from a ZIP archive, use the following syntax:
unzip filename.zip
Extracting specific files from a ZIP archive
You can also extract specific files from a ZIP archive using the following syntax:
unzip filename.zip file1 file2
This command will extract only 'file1' and 'file2' from the 'filename.zip' archive.
Overwriting existing files
By default, unzip will not overwrite existing files. To force it to overwrite existing files, use the -o option:
unzip -o filename.zip
In today's digital world, understanding how to compress and decompress files is crucial. The zip and unzip commands make light work of these tasks in macOS. Practice these commands, and you'll soon be a ZIP whiz!