#

Commands

Subscribe
Commands October 29, 2026·7 min read

How to Unzip Files in Linux

Run unzip archive.zip to extract a ZIP into your current directory, or unzip archive.zip -d destination to put the files somewhere else. Preview the contents with unzip -l archive.zip first. If files with the same names already exist, add -n to keep them or -o to replace them, then check that the files you expect are there.

Unzip a ZIP file from the Linux terminal

linux unzip command

Run unzip archive.zip in the terminal and replace archive.zip with the name of your file. The command looks for the ZIP in your current directory unless you give it a path. pwd shows which directory that is. The command does not automatically create a new folder named after the ZIP.

Install unzip if the command is missing

install unzip linux

If the terminal says unzip: command not found, the program is missing or not on your shell's command path. Install the unzip package with your distribution's package manager.

Linux distributionInstallation command
Ubuntu or Debiansudo apt install unzip
Fedora using DNFsudo dnf install unzip
Arch Linuxsudo pacman -S unzip

sudo authorizes the installation. You don't need it to unpack an ordinary ZIP in a folder you can write to.

Preview the ZIP and choose where the files will go

zip directory structure

The destination folder and the paths saved inside the ZIP decide where the files end up. Preview the paths with:

unzip -l archive.zip

-l lists the file names and sizes inside the ZIP. The output shows whether the ZIP has an outer project/ folder, several folders, or files at its top level.

A user in an r/linuxmint discussion asked: “Hi! How do i unzip a folder that has a file inside it and keep the folder structure(a file inside of a folder) after the folder is unzipped?”

Take a ZIP with three files:

archive.zip
├── project/README.txt
├── project/config/default.ini
└── other/README.txt

To put the files in a folder named extract, run:

unzip archive.zip -d extract

-d sets the destination. The result looks like this:

extract/
├── project/
│ ├── README.txt
│ └── config/
│ └── default.ini
└── other/
└── README.txt

extract is the destination you chose. project and other come from the paths saved in the ZIP.

extracted folder example

On Debian GNU/Linux 13 with Info-ZIP UnZip 6.00, all three files landed in extract with their folders intact.

If the ZIP already has an outer folder, -d keeps it. If the files are at the top level of the ZIP, they appear directly in the destination.

A nested destination such as parent-missing/leaf fails when its parent folder doesn't exist. Unzip then reports checkdir: cannot create extraction directory ... No such file or directory. Create the parent first:

mkdir -p parent-missing

The Ubuntu unzip(1) manual covers both -l and -d.

Keep existing files, overwrite them, or flatten the folder tree

unzip overwrite options

If the destination already holds files with the same names, you choose whether to keep them or replace them.

ModeWhen a destination file already existsUse when
Ordinary unzipAsks before replacing itYou want to decide interactively
-nSkips that fileYou need to keep the existing version
-oOverwrites without promptingYou intend to replace the existing version

Suppose you extracted project/README.txt and edited it. This command leaves the edited version in place:

unzip -n archive.zip -d extract

To restore the version from the ZIP, run:

unzip -o archive.zip -d extract

Why -j changes the folder layout

The -j option, short for junk paths, drops every folder level from the paths inside the ZIP. In the example ZIP, these two files:

project/README.txt
other/README.txt

both end up named README.txt.

flattened filename collision

Combine -n with -j and unzip skips one of them, because the flattened name already exists.

-j is the wrong option if you only want to drop an outer project/ folder, because it also flattens the folders inside it.

Extract one file, a subfolder, or more than one ZIP

select zip members

To extract one file, add its path as written inside the ZIP after the ZIP's name. For the configuration file in the example:

unzip archive.zip project/config/default.ini -d subset

The file ends up at subset/project/config/default.ini. To extract every file that matches a path pattern inside the ZIP, use:

unzip archive.zip 'project/config/*' -d subset

The quotes matter. Without them, the shell expands * against files on disk. With them, unzip receives the pattern and matches it against the names inside the ZIP.

Matching ZIP files on disk is a separate step. Say the folder holds several ZIPs and you run:

unzip *.zip

The shell passes each ZIP name as a separate argument. Info-ZIP reads every name after the first as a file to pull from the first ZIP, so you get filename not matched.

In a Unix-style shell, quote the pattern and Info-ZIP expands it itself, as its documentation describes:

unzip '*.zip'

If two ZIPs contain the same path, they write to the same file.

Check the ZIP and verify what was extracted

test zip integrity

-t tests the ZIP's data without extracting files to the destination:

unzip -t archive.zip

For quieter output, use:

unzip -tq archive.zip

On the three-file example, -tq prints “No errors detected...” and exits with status 0. The test checks data integrity only. It says nothing about malware or whether the files are safe to run.

One user in an r/linux4noobs discussion reported the error “empty archive” when trying to unzip a file.

verify extracted files

After extracting, check the output for errors or skipped files, then confirm that the files you expect are in the destination, such as project/README.txt and project/config/default.ini. Exit status 0 doesn't rule out skipped files, because -n skips them on purpose.

Troubleshoot common unzip errors

unzip error diagnosis
Error or symptomCauseWhat to check
cannot find or openWrong archive filename or pathCheck the spelling of the file name and the path you typed.
checkdir: cannot create extraction directoryA parent folder of the destination is missing, or the destination isn't writableCheck that every parent folder exists and that you can write to the destination.
permission deniedYou lack access to the ZIP or the destinationCheck the permissions and owner of both.
filename not matchedNo file in the ZIP matches your pattern, or the shell expanded it firstCompare your pattern with the names that unzip -l lists.
End-of-central-directory signature not foundWrong format, incomplete download or damaged ZIPCheck that the file is really a ZIP.
No space available for extractionThe destination filesystem is fullCheck the free space at the destination.
Unsupported compression or encryption methodYour extractor cannot process the method the ZIP usesFind out which method the ZIP uses and switch to a tool that supports it.
zip extraction errors

Don't use sudo unzip as a first fix for permission errors. Extracting as root can change file ownership, and a write into the wrong directory does more damage.

If the ZIP looks incomplete or damaged, go back to the original download and its source before trying any recovery.

When unzip is the wrong tool

linux archive formats

Each format has its own extraction tool.

  • .zip: Use a ZIP extractor such as Info-ZIP unzip.
  • .tar.gz or .tar.xz: These are compressed TAR archives. Extract them with a TAR tool, not unzip.
  • .gz: This usually names a gzip-compressed stream. It is not a ZIP, and it is not automatically a TAR archive.
archive format selection

Password-protected and AES-encrypted ZIPs

A password-protected ZIP prompts you for its password. Don't pass the password with -P password, because that exposes it through the command arguments.

A ZIP entry reported as compression method 99 can indicate AES encryption. A Red Hat AES compatibility note documents that error on Red Hat Enterprise Linux 5 with a legacy extractor and names 7-Zip as a compatible alternative.

NoScript Team
© 2026 No Script