The Linux Unzip Command

man using laptop
Paul Bradbury/Caiaimage/Getty Images

Zipping files is an easy, efficient way to transfer them between computers and servers using far less bandwidth than sending full-size files. When you receive a zipped archive in Linux, decompressing it is just as easy. Here are a few ways to use the unzip command in the Linux command line.

Decompressing a Single Zip File Into the Current Folder

The basic syntax for decompressing a file is:

unzip filename

As an example, say you've zipped up an album called "Menace To Sobriety" by the band Ugly Kid Joe as a zip file named "Menace To Sobriety."

To unzip this file into the current folder, simply run the following command:

unzip "Menace To Sobriety"

Decompressing Multiple Files

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

unzip filename1 filename2 filename3

Say you zipped up three files of Alice Cooper albums named "Trash," "Hey Stoopid," and "Dragontown" separately. To unzip these files, you might try entering the following:

unzip "" "" "Hey"

What you then get, however, is this error:

Archive: caution: filename not matched:<

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

unzip '*.zip'

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

Unzip a File but Exclude Certain Others

If you have a zip file and you want to extract all the files except for one, use the -x switch, as follows:

unzip -x

To continue with our example, the album "Trash" by Alice Cooper has a song titled "Bed Of Nails." To extract all the songs except for "Bed Of Nails," you'd use the following syntax:

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, like this:

unzip -d path/to/extract/to

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

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

To see all the songs in the album "," use the following:

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 OK before extracting it, use the -t switch:

unzip -t

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

unzip -t

Each file will be 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... "

Show Detailed Information About a Compressed File

If you would like more detailed information, use the -v switch, which outputs more verbose information:

The syntax is as follows:

unzip -v filename

For example:

unzip -v

The verbose output contains the following information:

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

Decompress a Zip File to the Current Directory Without Creating Directories

If you added folders within a zip file while creating it, then the standard unzip command will recreate the folder structure as it is unzipped.

For example, if you extract a zip file called "" with the following structure, the folders will be recreated when you unzip it:

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

If you want all the ".txt" files to extract into the current folder without the folders being recreated, you'd use the -j switch, as follows:

unzip -j

Decompress a File Without Prompting When Files Already Exist

Imagine you have a zip file that you've already unzipped, and you've started working on the files that you have extracted.

If you have another file you want to unzip and the zip file contains files that already exist in the target folder, a warning is displayed before the system overwrites the files. This is OK, but if you are extracting a file with 1000 files in it, you don't want to be prompted every time.

So, if you don't want to overwrite existing files, use the -n switch:

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:

unzip -o

Extracting 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:

unzip -P kittens123

Unzipping a File Without Displaying Any Output

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

unzip -q

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

Linux provides dozens of other switches. Visit the Linux man pages to learn more.

Was this page helpful?