Introduction

If you downloaded a file that ends in .tar.gz or .zip, this indicates that it has been compressed. This guide will walk you through unzipping a zipped file in Ubuntu.

tutorial on how to unzip a file in ubuntu

Prerequisites

  • Access to a terminal window/command-line (Ctrl-Alt-T)
  • Zip/unzip utility (included by default)

How to Install the Zip and Unzip Utility in Ubuntu

Ubuntu distributions usually include the zip and unzip utilities. If for some reason your’s does not, use the following command to install it:

sudo apt-get install zip unzip

The output in our example confirms that the latest version is already installed:

Install the zip and unzip features command example

Unzip a File Using the Command Line

This guide assumes that you’ve already downloaded a file that has been zipped, and that you know where it’s located. Let’s assume that we have downloaded a file called test.zip to the /home/user/Documents/ directory.

Start by opening a command-line (also called a terminal window). By default, you should start in the /home/user/ directory.

To list the contents of the directory you’re currently viewing enter:

ls

Ubuntu will color-code different entries.

List of file and folders in the Home directory

Directories are colored blue, regular files are colored white (the same as the text you type).

To change to the Documents directory, use the command:

cd Documents

As the folder only contains the test.zip file, the output look like this:

Content of Documents folder after unzipping


Note the capitalized D in Downloads. It is necessary to type the name of the directory exactly as you see it on the screen. Linux treats /Downloads/ and /downloads as two different directories.


Enter ls again. And you’ll get a different listing – the content of the Documents folder.

To unzip the test.zip file, enter the following:

unzip test.zip

The system will decompress the test.zip file, and place a copy of the contents in the /Documents directory.


Normal copying conventions apply. If the test.zip file contains a file named document.txt, and a file with that name already exists in the target directory, the system will ask if you want to overwrite the file


Other Linux Unzip Commands

The zip and unzip commands can be used with additional options to have more control over how they work. Here are just a few common ones.

How to Unzip Multiple ZIP Files

For example the folder /Documents/zipped has several files zipped in it. Use the cd command to change to that directory:

cd zipped

To unzip all the files in that directory.:

unzip “*.zip”

The * sign is a wildcard, which means “any number of any characters.” So, any file that ends in .zip would be found and unzipped by entering this command.

How to Test If a ZIP File Is Valid

You can use the –t option with the zip command to test the file first. Enter the following:

unzip -t test.zip

This is useful if you think the zipped file has been damaged or corrupted.

The screen confirms that all the files are OK and that no errors were reported.

The system will tell you if it detects any errors (or if it doesn’t).

How to Exclude Files When Unzipping a ZIP File

Some zip files have several different files included in them. You can extract all of them, or you can exclude some of them.

To exclude a particular file:

unzip test.zip –x a_particular_file.txt

This would prevent the file a_particular_file.txt from being extracted from the zip file.

How to List the Contents of a Zip File

To view a list of the contents of a zip file use the -l command:

unzip -l test.zip

The output lists the files within the test.zip folder.

List of files within test.zip.

Extract a ZIP File to a Different Directory

To specify that you want to unzip the files to a different destination than the directory you’re in,  type the command:

unzip test.zip –d /home/user/destination

The –d switch tells the system to put the unzipped files somewhere else. You can substitute the path to a location of your choice for /home/user/destination.

Conclusion

You now know how to use Ubuntu to unzip and access the content of Zip Files in Linux.