Unzip a Directory in Linux: 10 Example Commands

Last updated Sunday, March 15, 2026 10:19 am 9 min read 1 comment

Zip archives still show up everywhere, from project downloads and backups to file bundles shared across Windows and Linux systems. To unzip to another directory in Linux, use unzip archive.zip -d /path/to/destination. The same unzip command in Linux also lists archive contents, tests archive integrity, and skips files you do not want to extract.

unzip is already available on many desktop and server installations, but minimal images and containers sometimes leave it out. Most readers only need a quick availability check, the -d extraction pattern, and a short list of the errors that point to a bad path or the wrong archive format.

Understand the unzip Command

The unzip command extracts .zip archives from the terminal while preserving the directory structure stored inside the archive. If you also work with tarballs, use a different workflow to extract .gz and .tgz files in Linux, because unzip only handles ZIP archives.

Check Whether unzip Is Already Available

Before you install anything, check whether unzip is already on your system:

command -v unzip

A successful result usually looks like this:

/usr/bin/unzip

If the command prints a path, unzip is installed and ready to use. It is a better first check than unzip -v when you only want to confirm the binary exists, because it avoids a long build-information dump. If it prints nothing or your shell reports unzip: command not found, install the package with the commands in the next section.

unzip Command Syntax

The basic syntax is short:

unzip [options] archive.zip [-d destination]

Each part controls a different part of the extraction process:

  • unzip runs the extraction command.
  • [options] changes how extraction works, for example -o to overwrite files or -n to keep existing files.
  • archive.zip is the ZIP file you want to inspect or extract.
  • [-d destination] sends the extracted files to another directory instead of the current one.

At its simplest, unzip archive.zip extracts everything into the current directory. To send the same archive somewhere else, append -d /path/to/destination.

Common unzip Options by Task

This quick reference groups the most useful options by what you are trying to do:

TaskCommand or OptionWhat It Does
Extract into the current directoryunzip archive.zipUnpacks the entire archive where you are currently working.
Extract to another directory-d /path/to/destinationSends the extracted files to a different location and creates the destination directory if needed.
List contents without extracting-lShows file names, sizes, and stored paths without changing anything on disk.
Show a detailed listing-vDisplays compression methods, ratios, CRC values, and timestamps.
Test archive integrity-tChecks the archive for corruption before you extract it.
Overwrite existing files-oReplaces matching files without asking for confirmation.
Keep existing files-nSkips files that already exist in the destination.
Flatten stored directories-jExtracts files without recreating the directory tree stored in the archive.
Exclude files or directories-x patternSkips anything that matches the supplied pattern.
Restore extra Unix attributes-XRestores supported extended attributes when the archive contains them.

You can combine options when they solve different problems. For example, unzip -q -o archive.zip -d /tmp/extract overwrites files quietly into a different directory.

Install the unzip Command

If command -v unzip returns nothing, install the package from your distribution repositories:

# Ubuntu and Debian
sudo apt install unzip

# Fedora, RHEL, Rocky Linux, and AlmaLinux
sudo dnf install unzip

# Arch Linux and Manjaro
sudo pacman -S unzip

# openSUSE
sudo zypper install unzip

# Alpine Linux
sudo apk add unzip

# Gentoo
sudo emerge app-arch/unzip

After installation, rerun command -v unzip to confirm that the binary is on your PATH.

On Alpine or other BusyBox-heavy environments, install the standalone unzip package when you want the full Info-ZIP option set. Minimal archive utilities do not always match the same flags or output format.

Practical unzip Command Examples

Most unzip work comes down to four things: extracting archives, checking what is inside them, verifying that the ZIP file is intact, and controlling how existing files are handled.

Extract to a Specific Directory

When you want the extracted files to land in a dedicated folder instead of your current working directory, use -d. Here, -d means destination directory. If the folder does not exist yet, you can create directories with mkdir, or let unzip create the destination automatically.

unzip archive.zip -d /path/to/destination

A run like this starts extracting the stored files into the destination directory:

Archive:  archive.zip
  inflating: /path/to/destination/file1.txt
  inflating: /path/to/destination/notes.txt
  inflating: /path/to/destination/file2.txt

This is the core pattern behind most unzip to directory searches: keep the archive where it is and send the extracted files to a different location.

Extract in the Current Directory

If you are already standing in the directory where the files should land, run unzip without any extra options:

unzip archive.zip

This extracts the archive contents into the current directory and recreates any folders stored inside the ZIP file.

Extract Multiple Archives at Once

When a directory contains several ZIP files, a short loop can process all of them. Sending each archive into its own directory avoids filename collisions between different extracts.

for archive in *.zip; do
  [ -e "$archive" ] || continue
  unzip "$archive" -d "${archive%.zip}"
done

This loop skips the body if no ZIP files are present, then extracts each archive into a directory named after the archive file. If those generated folder names need cleanup later, you can rename directories with mv.

Overwrite Existing Files Without Prompting

Automated workflows break when unzip pauses to ask whether a file should be replaced. Use -o when you want the archive copy to win every time.

unzip -o archive.zip

This replaces existing files with matching names without interactive prompts, which makes it suitable for scripts and repeatable deployment steps.

Skip Overwriting Existing Files

Use -n when local files should stay untouched and you only want missing files from the archive:

unzip -n archive.zip

This keeps existing files in place and extracts only the files that are not already present in the destination directory.

List Archive Contents Without Extracting

Before you unpack anything, check the archive contents with -l:

unzip -l archive.zip

A standard listing looks like this:

Archive:  archive.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     6  2026-03-15 10:16   file1.txt
    11  2026-03-15 10:16   notes.txt
     5  2026-03-15 10:16   file2.txt
---------                     -------
    22                     3 files

This is the safest way to confirm filenames, sizes, and stored paths before extraction.

Show Detailed Archive Information

When you need more than filenames, use -v for a verbose listing. Compression ratios, timestamps, and CRC values vary by archive, but the output format looks like this:

unzip -v archive.zip
Archive:  archive.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
     6  Defl:N        8 -33% 03-15-2026 10:16 9f606eec  file1.txt
    11  Defl:N       13 -18% 03-15-2026 10:16 f7293622  notes.txt
     5  Defl:N        7 -40% 03-15-2026 10:16 e6e3a775  file2.txt
--------          -------  ---                            -------
    22               28 -27%                            3 files

Use this view when you need CRC data, stored timestamps, or compression ratios before you decide whether to extract the archive. For very small files, negative compression percentages are normal because ZIP metadata can be larger than the original content.

Test Archive Integrity Before Extraction

If the archive came from an unreliable download or a third-party source, run an integrity test before extracting it:

unzip -t archive.zip

A clean archive returns output like this:

Archive:  archive.zip
  testing: file1.txt                OK
  testing: notes.txt                OK
  testing: file2.txt                OK
No errors detected in compressed data of archive.zip.

If any file fails, stop there and replace the archive before you scatter partial or damaged files across your system.

Restore Extended Attributes and Permissions

Archives created on Unix-like systems can store more than plain file contents. Use -X when you want unzip to restore supported extended attributes in addition to the normal stored file metadata.

unzip -X archive.zip

This is most useful for archives created on Linux or other Unix-like systems. If you need to adjust the results afterward, you can change file permissions with chmod.

Exclude Specific Files or Patterns

Many ZIP files contain logs, temporary files, or platform-specific metadata you do not need. Use -x to skip matching paths during extraction:

unzip archive.zip -x '*.log' '__MACOSX/*'

This extracts everything except files matching *.log and the macOS metadata directory __MACOSX/. Add more patterns as needed, separated by spaces.

Troubleshoot Common unzip Errors

These are the unzip problems readers hit most often when the archive path is wrong, the package is missing, or the file is not a valid ZIP archive.

Fix unzip: command not found

If your shell returns this error:

bash: unzip: command not found

The unzip package is not installed, or the binary is not on your shell PATH. Install the package for your distribution, then verify the command location:

command -v unzip

A working result usually prints a full path like this:

/usr/bin/unzip

Fix End-of-central-directory Signature Errors

If unzip prints an error like this:

End-of-central-directory signature not found.  Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive.

The file is either damaged, incomplete, or not a real ZIP archive even if it ends in .zip. Test the archive directly before extracting it:

unzip -t archive.zip

A healthy archive ends with output like this:

No errors detected in compressed data of archive.zip.

If the test fails, download the archive again and confirm that the source actually provides a ZIP file rather than another archive format.

Fix cannot find or open archive.zip

If you run unzip from the wrong directory or misspell the archive name, you will see an error like this:

unzip: cannot find or open archive.zip, archive.zip.zip or archive.zip.ZIP.

Use the full archive path and point unzip at a directory you know exists. If needed, create the destination first:

mkdir -p "$HOME/extract"
unzip "$HOME/Downloads/archive.zip" -d "$HOME/extract"

Once the path is correct, extraction begins like this:

Archive:  /home/user/Downloads/archive.zip
  inflating: /home/user/extract/file1.txt

unzip Command FAQ

Does unzip create the destination directory automatically?

Yes. When you run unzip archive.zip -d /path/to/destination, unzip creates the destination directory if it does not already exist, then extracts the archive contents there.

What is the difference between unzip -l, unzip -t, and unzip -v?

unzip -l lists filenames and sizes without extracting anything. unzip -t tests the archive for corruption. unzip -v shows a more detailed listing with compression methods, ratios, CRC values, and timestamps.

Can unzip extract a single file instead of the whole archive?

Yes. Add the stored path after the archive name, for example unzip archive.zip path/inside/archive.txt. That extracts only the requested file or directory instead of the full archive.

Why can unzip on Alpine or BusyBox look different from other Linux systems?

Alpine can install the standalone Info-ZIP package with apk add unzip, and that package uses the same unzip syntax as the standard Info-ZIP tool on other Linux distributions. Very small BusyBox-based environments may rely on different archive utilities with a reduced flag set, so install the standalone unzip package when you want the full Info-ZIP option set.

Conclusion

unzip is ready for the ZIP jobs that come up most often on Linux, whether you need a clean destination directory, a quick contents check, or an integrity test before extraction. When the file is not a ZIP archive at all, switch to the matching archive tool instead of forcing unzip onto the wrong format.

Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

1 thought on “Unzip a Directory in Linux: 10 Example Commands”

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Leave a Comment

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: