Practical Examples For The Linux Unzip Command

man using laptop
Paul Bradbury/Caiaimage/Getty Images


In a previous guide I showed you practical ways to use the Linux zip command.

This article is the yang to that ying and shows you practical examples for decompressing files using the Linux unzip command.

How To Decompress A Single Zip File Into The Current Folder

The basic syntax for decompressing a file is as follows:

unzip filename

I have zipped up an album called "Menace To Sobriety" by the band "Ugly Kid Joe" as a zip file called "Menace To Sobriety".

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

unzip "Menace To Sobriety"

Decompressing Multiple Files

The man command states that you can decompress multiple files using the following syntax:

unzip filename1 filename2 filename3

As an example I have three Alice Cooper albums called "Trash", "Hey Stoopid" and "Dragontown" which I have zipped up as separate files.

To unzip these files all I need to do is enter the following:

unzip "" "" "Hey"

In reality however, what really happens when I run that command is that I receive the following error:


caution: filename not matched:

The easiest way to unzip multiple files is to use the following instead:

unzip '*.zip'

Be careful because this is indiscriminate and will decompress every zip file in the current folder.

Unzip a file but exclude certain files

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

unzip -x

As an example the album "Trash" by Alice Cooper has a song called "Bed Of Nails". If I wanted to extract all the songs except for "Bed Of Nails" then I would 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 to the current one use the -d switch as follows:

unzip -d path/to/extract/to

For example to decompress the "" file to /home/music/Alice Cooper/Trash I would 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 "" all I have to do is use the following syntax:

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 I would run the following:

unzip -t

Each file will be listed within the file and the word "OK" should appear next to it. At the bottom of the output a message should appear stating "no errors detected in compressed data of <filename>".

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 %
  • Date and Time Created
  • CRC
  • Name

Decompress A Zip File To The Current Directory Without Creating Directories

If whilst creating a zip file you added folders with that zip file then the standard unzip command will recreate the folder structure as it is unzipped.

For example if I have a zip file called with the following structure and extract it the folders will be recreated when I unzip it:

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

If I wanted all the .txt files to extract into the current folder without the folders being recreated I would 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 have already unzipped and you have started working on the files that you have extracted.

If you have another file you want to unzip then if that zip file contains files that already exist in the place they are to be extracted a warning is displayed before overwriting them.

This is ok but if you are extracting a file with 1000 files in it you don't want to be prompted every time.

If you don't want to overwrite files that already exist you can supply the -n switch as follows:

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 as follows:

unzip -o

Extracting Password Protected Zip Files

If you need to unzip a file which requires a password to access then 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

How To Unzip A File Without Displaying Any Output

By default the unzip command lists everything it is doing including list 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.


There are literally dozens of other switches available and you can use the Linux man pages to find out what they are.

Click here for a web page version of the Linux unzip command man page.

More From Us