The Linux 'unzip' Command

There are several ways to unzip files using this command

Zipping files is an easy, efficient way to transfer data between computers and servers. When files are compressed, they not only save disk space on a local drive but also make it easier and more convenient to download files from the internet, using far less bandwidth than sending full-size files.

Person unzipping files via the command line
Lifewire / Ashley Nicole DeLeon

When you receive a zipped archive in Linux, decompressing it is just as easy. There are lots of switches available in Linux, which means that you have many ways to extract files with the unzip command in the command line.

Decompress Single ZIP Files

The basic syntax for decompressing a file is:

unzip filename

As an example, say you've zipped up an album named Menace to Sobriety. To unzip this file to the current folder, you'd simply run the following command:

Screenshot showing how to use the unzip command in Linux
unzip "Menace To Sobriety"

Decompress Multiple ZIP Files

The man command lets you decompress more than one file at a time using the following syntax:

unzip filename1 filename2 filename3

If you've zipped up three files of Alice Cooper albums named Trash, Hey Stoopid, and Dragontown, separately, you might try this to unzip them:

Screenshot of unzip errors in Ubuntu
unzip "" "" "Hey"

However, what you'd get is this error:

Archive: caution: filename not matched:

Assuming the three files live in the same folder, a better method is to use the following command:

Screenshot of the Ubuntu unzip command opening multiple ZIP files at once
unzip '*.zip'

Be careful, though. This command is indiscriminate and will decompress every ZIP file in the current folder.

Exclude Some ZIP Files

If you have a ZIP file and you want to extract all the files except for one, use the -x switch.

unzip -x

To continue with our example, the album "Trash" in has an MP3 titled Bed Of Nails. To extract all the songs except for "Bed Of Nails," you'd do this:

Screenshot showing how to unzip everything but one file from a ZIP archive in Ubuntu
unzip -x "Bed Of Nails.mp3"

Extract a ZIP File to a Different Directory

If you want to put the contents of the ZIP file in a different directory than the current one, use the -d switch.

unzip -d path/to/extract/to

For example, to decompress the file to /home/music/Alice Cooper/Trash, you'd use the following syntax:

Screenshot showing how to use the unzip command to extract files to a different folder
unzip -d "/home/music/Alice Cooper/Trash"

How to Show the Contents of a Compressed Zip File

To list the contents of a compressed file, use the -l switch.

unzip -l

In our example, we could use this switch to see all the files in

Screenshot of the unzip command with the -l switch in Ubuntu
unzip -l

The information returned includes:

  • Length in bytes
  • Date created
  • Time created
  • Name

How to Test If a ZIP File Is Valid

To test whether a ZIP file is structured correctly and can be used properly before extracting it, use the -t switch.

unzip -t

For example, to test whether is valid, you could run the following:

Screenshot showing how to use the -t switch in Ubuntu to test a ZIP file
unzip -t

Each file is listed, and OK should appear next to it. At the bottom of the output, a message should appear stating no errors detected in compressed data of....

See Detailed Information on a ZIP File

The -v switch (verbose) can give more detailed information.

unzip -v filename

To use this switch with to see more information, we'd type:

Screenshot showing how to use the -v switch in Ubuntu
unzip -v

The output contains the following information:

  • Length in bytes
  • Method
  • Size
  • Compression percentage
  • Date and time created
  • CRC
  • Name

Decompress a ZIP File Without Making Directories

For ZIP files that have folders, executing unzip alone, without switches, would re-create the same folder structure from the archive.

Extracting, for example, which has the following three folders, would result in the same folders being extracted:

  • Folder 1: filea.txt, fileb.txt, filec.txt
  • Folder 2: filed.txt, filee.txt
  • Folder 3: filef.txt

In this example, to extract all of the TXT files to the current folder without making those three folders, just append -j to the end of the command.

Screenshot showing how to use the -j switch with the unzip command in Ubuntu
unzip -j

Decompress a ZIP File Without Prompting to Overwrite

Suppose you've already unzipped a particular ZIP file and have started working on the unzipped files, changing and updating them however you wish. The last thing you want is to have those files overwritten when you extract a ZIP that has files with those same names. You'd immediately lose everything you were working on when the new files replace your existing ones.

However, you can use the -n switch if you want to not overwrite existing files. Every file from the ZIP archive that has a name matching a file in the extracted folder will not overwrite anything when this switch is used. Everything else, however, that has a unique name will still be extracted.

unzip -n

If you don't care whether the file already exists and you always want to overwrite the files as they are extracted without prompting, use the -o switch.

Screenshot of the -o switch used with the unzip command in Ubuntu
unzip -o

Extract Password-Protected ZIP Files

If you need to unzip a file that requires a password for access, use the -p switch followed by the password.

unzip -P password

For example, to unzip a file called with the password kittens123, use the following:

Screenshot of the unzip command used with the -p switch in Ubuntu
unzip -P kittens123

Unzip a File Without Displaying Any Output

By default, the unzip command lists everything it's doing, including showing every file in the archive as the command is extracting them. You can suppress this output by using the -q switch.

Screenshot of the -q switch used with the unzip command in Ubuntu
unzip -q

This unzips the filename without providing any output and returns you to the cursor when it has finished.