How to Unzip Files Using Mac Terminal
July 15, 2026
Bookmark this as a reference — the specific flags below cover nearly every extraction scenario you'll realistically encounter from the command line.
For anyone comfortable working in Terminal, or scripting a repeatable extraction task, the command-line route is often faster than switching to a GUI app for a single operation. This is a complete reference for extracting archives via Terminal on macOS — covering ZIP, TAR.GZ, and the specific flags for password protection, verbose output, and selective extraction.
Why macOS ships these tools built in
It's worth understanding why unzip and tar come pre-installed on every Mac while RAR and 7Z tools require separately installing Homebrew and a package, since this distinction reflects the same underlying licensing and format-openness pattern covered throughout this site. ZIP and TAR/GZIP are both open, royalty-free formats with origins deeply tied to Unix and early internet infrastructure — Apple can freely bundle support for them without any licensing consideration. RAR is proprietary, and 7Z, while fully open-source, simply was never adopted into macOS's base toolset the way TAR and GZIP were, likely because those two already covered Apple's baseline requirements for a Unix-derived operating system.
Basic ZIP extraction
macOS ships with the standard unzip command built in, no installation required:
unzip archive.zip
This extracts into the current directory by default. To extract into a specific destination instead:
unzip archive.zip -d /path/to/destination
The -d flag specifies the destination folder, creating it if it doesn't already exist.
Extracting a password-protected ZIP
unzip -P yourpassword archive.zip
The -P flag passes the password directly on the command line. Security-conscious note: this leaves the password visible in your shell history in plain text. For anything genuinely sensitive, omit -P and let unzip prompt interactively instead:
unzip archive.zip
If the archive requires a password, unzip will prompt for it without echoing your input to the screen, and without leaving it recorded in your command history.
Listing contents without extracting
unzip -l archive.zip
This displays the complete file listing, including individual file sizes, without extracting anything — useful for checking a large archive's contents before committing to a full extraction, similar in purpose to a GUI app's preview feature but text-based.
Extracting specific files only
unzip archive.zip "path/to/specific-file.txt"
Pass the exact internal path (found via the listing command above) to extract only that file rather than the entire archive. Multiple specific files can be listed together in one command, each as a separate quoted argument.
Verbose output for troubleshooting
unzip -v archive.zip
Shows detailed information about each file as it processes, including compression ratio per file — useful when diagnosing exactly where in a large archive an extraction failure is occurring, since the default output is otherwise fairly minimal.
Testing an archive's integrity without extracting
unzip -t archive.zip
Verifies the archive's internal checksums without writing any files to disk — a fast way to confirm a large or important archive isn't corrupted before committing to a full extraction, particularly useful after a large download you want to sanity-check first.
Extracting TAR.GZ archives
tar -xzf archive.tar.gz
Breaking down the flags: -x extracts, -z decompresses using gzip first, -f specifies the filename that follows. For the related .tar.bz2 format, swap -z for -j; for .tar.xz, swap it for -J. See our dedicated TAR.GZ guide for more detail on this two-part format.
Extracting RAR files via Terminal
Unlike ZIP and TAR, macOS has no built-in RAR support at all, even via Terminal. You'll need Homebrew and the unar package:
brew install unarunar yourfile.rar
This handles password-protected and multi-part RAR archives as well, prompting interactively for a password when needed.
Extracting 7Z files via Terminal
Also requires Homebrew, since 7Z has no built-in macOS support either:
brew install sevenzip7z x yourfile.7z
The x flag extracts with full folder structure preserved (as opposed to e, which flattens everything into the current directory, ignoring the archive's internal folder structure).
Batch extracting multiple archives in one command
for f in *.zip; do unzip "$f"; done
This loop extracts every ZIP file in the current directory sequentially, useful for scripting a repeated extraction task across many files at once, similar in outcome to a GUI app's batch extraction feature but scriptable and automatable.
A realistic scenario: a developer automating archive processing
Picture a developer who receives nightly data exports as compressed archives from an automated pipeline, needing to extract and process them as part of a larger script. Terminal commands, embedded directly into a shell script, allow this entire extraction step to run unattended as part of a larger automated workflow — something a GUI app, requiring manual interaction, simply can't do. This is exactly the scenario where Terminal's command-line approach has a genuine, unmatched advantage over any GUI archive tool, regardless of how polished that tool's interface might be.
Keeping a personal reference for the commands you use most
Given how many flags and variations exist across these commands, it's genuinely reasonable to keep a personal cheat sheet — a simple text file or Notes entry with the two or three specific command patterns you actually use regularly — rather than relying on memory or re-searching each time. Terminal syntax fluency comes from repetition, and even experienced developers commonly keep quick-reference notes for commands used infrequently enough to not become fully automatic.
When Terminal isn't the better choice
For one-off, occasional extraction — the majority of everyday archive use — a GUI app is generally faster in practice, since you avoid remembering exact flag syntax, navigating to the correct directory manually, and the various small frictions Terminal use involves for anyone not already working there for other reasons. Terminal's real advantage is specifically for scripting, automation, and situations where you're already deep in a command-line workflow for other tasks.
Excluding specific files or patterns during extraction
unzip archive.zip -x "*.DS_Store" "__MACOSX/*"
The -x flag excludes files matching the given patterns from extraction — useful specifically for skipping macOS metadata files that sometimes get included when an archive was created on a Mac, or any other pattern of files you know you don't need from a specific archive.
Overwriting versus skipping existing files
By default, unzip prompts interactively when extraction would overwrite an existing file, asking whether to replace, skip, or rename. For scripted use where no interactive prompt is possible, two flags control this behavior explicitly: -o forces overwrite without prompting, while -n never overwrites, automatically skipping any file that would conflict with an existing one. Choosing the appropriate flag matters specifically for automated scripts, where an unexpected interactive prompt would otherwise cause the script to hang indefinitely waiting for input that never comes.
Creating a ZIP archive via Terminal, not just extracting one
The reverse direction is equally straightforward:
zip -r archive.zip /path/to/folder
The -r flag recurses into the folder's full contents. To add password protection during creation:
zip -er archive.zip /path/to/folder
Combining -e (encrypt, triggers an interactive password prompt) with -r. See our complete folder-zipping guide for the full walkthrough of both Finder and Terminal methods together.
Troubleshooting
- "command not found: unzip" or similar: extremely rare on a standard macOS install, since these tools ship built-in — verify you haven't modified your shell's PATH in a way that excludes system binaries.
- Permission denied when extracting to a specific destination: verify you have write permissions for that destination folder, or extract to your home directory first and move the result afterward.
- unzip fails on a very new ZIP with an unfamiliar compression method: macOS's built-in unzip version can lag behind the latest ZIP specification updates — a third-party tool sometimes handles newer compression methods more reliably.
Chaining extraction with other commands
One of Terminal's genuine advantages is the ability to chain extraction directly into a larger pipeline of commands, something no GUI app can replicate. For example, extracting an archive and immediately searching its contents for a specific string in one line:
unzip -p archive.zip filename.txt | grep "search term"
The -p flag pipes the extracted file's contents directly to standard output rather than writing it to disk, which then feeds into grep for searching — useful for quickly checking whether an archive contains a specific piece of text without a separate extract-then-search process. This kind of composability, chaining simple commands together into more complex operations, is a core strength of the Terminal approach that a GUI interface fundamentally can't offer in the same way.
Frequently asked questions
Is Terminal extraction faster than a GUI app? For the actual extraction process itself, speed is comparable — the time difference people notice is in the surrounding workflow (typing commands versus clicking), not the underlying decompression speed.
Can I combine multiple Terminal extraction steps into one script? Yes — this is exactly where Terminal's advantage over GUI tools becomes significant, since multiple extraction, verification, and processing steps can be chained together in one automated script.
Does Terminal extraction handle the same formats a GUI app does? With Homebrew installed for RAR and 7Z support, yes — Terminal can match a GUI app's format coverage, just without the visual preview and drag-and-drop convenience.
The bottom line
Terminal extraction is genuinely powerful for scripting and automation, with built-in ZIP and TAR support plus Homebrew-installable RAR and 7Z tools covering every common format. For everyday, one-off extraction, Unzipr offers the same format coverage with a faster, more visual workflow — drag, preview, extract, no syntax to remember, no flags to look up mid-task.