Extract .zip Files in Mac Terminal

Extracting .zip files in Mac Terminal is a simple process that can be done using the built-in unzip command. This method is efficient for handling compressed files, especially if you prefer using the command line or need to automate extraction tasks.

In this guide, we’ll walk you through how to extract .zip files using unzip command in Mac Terminal.

Basic Usage of the unzip Command

The unzip command is used to extract the contents of a .zip archive. The basic syntax for extracting a file is as follows:

unzip archive_name.zip

In the following example, mydir.zip is the name of the compressed file you want to extract. The contents will be extracted to the current directory.

Extracting a Zip File to a Specific Directory

If you want to extract the contents of a zip file to a specific directory, use the -d option, followed by the destination path. For example, to extract archive.zip to a folder called Documents, use the following command:

unzip archive.zip -d ~/Documents

This will extract all the contents of the .zip file into the Documents folder.

In the following example, we extracted mydir.zip to Documents folder.

Listing the Contents of a Zip File Without Extracting

If you want to see the contents of a .zip file without extracting it, you can use the following command:

unzip -l archive_name.zip

This will display a list of the files inside the archive along with their sizes and file paths, but it won’t extract anything.

For example, in the following, we listed the files inside the archive mydir.zip.

Overwriting Files During Extraction

By default, the unzip command will prompt you before overwriting any existing files during extraction. If you want to automatically overwrite files without being prompted, use the -o option:

unzip -o archive_name.zip

This will extract the files and overwrite any existing files with the same names in the current directory.

For example, in the following, we unzipped the archive mydir.zip with the override option.

Extracting Password-Protected Zip Files

If the zip file is password-protected, the unzip command will prompt you to enter the password. For example, when you run:

unzip archive_name.zip

The Terminal will ask for the password. Once you enter it, the file will be extracted.

Extracting Specific Files from a Zip Archive

If you only want to extract specific files from a .zip archive, you can specify the file names in the command. For example, to extract only file1.txt and file2.txt from archive_name.zip, use this command:

unzip archive_name.zip file1.txt file2.txt

This will extract only the specified files from the archive.