How to Unzip Archives on Ubuntu

This guide will teach you how easy it is to unzip archives on the Ubuntu operating system.

Unzip Files on Ubuntu

A zip file is a type of archive that has been compressed using a lossless algorithm.

It has been a popular format for bundling files together for a considerable time, and you have likely downloaded ZIP archives to your Ubuntu system before.

You can typically tell that a file is a zip archived as it has the file extension, “.zip“.

Unzipping files on Ubuntu is a straightforward process on both the desktop and server versions of Ubuntu.

For the command line, we will be installing a package called unzip to Ubuntu. This package is straightforward to use within the terminal.

If you are using Ubuntu’s desktop version, you will already have a desktop application available to you to unzip these files.

The following steps on unzipping a zipped file will work on every version of Ubuntu, including Ubuntu 18.04 and Ubuntu 20.04.

Table of Contents

Using Unzip using the Command Line on Ubuntu

The following steps will focus on how to unzip a file on Ubuntu using the command line.

You can also use this method for extracting archives over a remote connection such as SSH.

If you are using the desktop version of Ubuntu and want to use the terminal, you can open it quickly by pressing CTRL + ALT + T.

Installing the unzip Package to Ubuntu

Before you can unzip a zipped archive on Ubuntu, you will need to install a package.

The unzip package is what allows you to extract the files out of a .zip archive.

To install the unzip package using apt, all you need to do is run the following command.

sudo apt install unzip

When installing this package, you will be asked to enter your user’s password.

The Basics of Extracting an Archive using unzip

If you want to extract all of the contents of an archive to the current directory, then using the unzip command is simple.

The basic syntax of the unzip command on Ubuntu is the following. It is just “unzip” followed by the filename of the archive.

unzip ZIPFILENAME

When using the syntax above, make sure that you swap out ZIPFILENAME with the archive’s name.

Example of Extracting an Archive

For example, let us assume that we have a zip archive called “pimylifeup.zip“.

All we need to do to extract the contents of this zip archive to the current directory is to use the following command.

unzip pimylifeup.zip

During the extraction process, you will notice that the unzip command prints out the name of every file that it extracts.

Below is an example of what the unzip command outputted on our Ubuntu system.

Archive:  pimylifeup.zip
   creating: pimylifeup/
 extracting: pimylifeup/howtounzipfiles
 extracting: pimylifeup/example.doc
 extracting: pimylifeup/ubuntu
 extracting: pimylifeup/tutorial.txt
 extracting: pimylifeup/pimylifeup.com
 extracting: pimylifeup/readme

Quieting the unzip Command

Having the unzip command fill out your Ubuntu’s terminal with hundreds of lines can be cumbersome.

It is possible to stop the unzip command from outputting the extracted files’ names by using the “-q” argument.

Below you can see the syntax of extracting an archive without outputting the details.

unzip -q ZIPFILENAME

The only difference between this and the basic command is that it doesn’t output each extracted file’s name.

unzip to a Different Directory

You don’t have to use use the unzip command to extract the files to the same directory.

Using the “-d” argument, we can tell unzip that we want the files to be extracted to the directory that we specify.

Unlike the quietargument, this one needs to be specified after the name of your file archive.

unzip ZIPFILENAME -d /path/to/directory

To use this version of the command, swap out “ZIPFILENAME” with the name of your archive and “/path/to/directory” with the path to where you want the files extracted.

Example of Unzipping an Archive to a Certain Directory

To show you how this works on Ubuntu, we will be using unzip on an archive called “pimylifeup.zip” to the “/home/pimylifeup/exampledir/” directory.

Below you can see that this command is relatively easy to use as long as you know the filename and directory.

unzip pimylifeup.zip -d /home/pimylifeup/exampledir/

Below you can see an example of what the output produced by this command would look like.

Archive:  pimylifeup.zip
   creating: /home/pimylifeup/exampledir/pimylifeup/
 extracting: /home/pimylifeup/exampledir/pimylifeup/howtounzipfiles
 extracting: /home/pimylifeup/exampledir/pimylifeup/example.doc
 extracting: /home/pimylifeup/exampledir/pimylifeup/ubuntu
 extracting: /home/pimylifeup/exampledir/pimylifeup/tutorial.txt
 extracting: /home/pimylifeup/exampledir/pimylifeup/pimylifeup.com
 extracting: /home/pimylifeup/exampledir/pimylifeup/readme

Using unzip on a Password Protected Archive

Sometimes you might download a zip archive that is protected using a password.

You can use the unzip command on Ubuntu to extract these files by including the password as an argument.

When running the command, you need to use “-P” followed by the archive’s password.

unzip -P PASSWORD ZIPFILENAME

When using the command like this, make sure you replace “PASSWORD” with the archive’s password and “ZIPFILENAME” with its filename.

Example of using unzip on a Protected Archive

For this example, we will assume we have a zip file called “pimylifeup.zip” protected using the password “ubuntu“.

unzip -P ubuntu pimylifeup.zip

If you have gotten the password correct, then the unzip software will extract the files to the current directory.

Using unzip to test if a Zip is Valid on Ubuntu

If you want to make sure that the zip archive is valid and not corrupt, then the unzip command has the functionality to validate them.

Using the “-t” option alongside the unzip command on Ubuntu, you can validate the file.

unzip -t ZIPFILENAME

This option tests the file by extracting each file and ensuring each piece is extracted without errors.

Example of using unzip to Test an Archive

For this example, we will test our “pimylifeup.zip” archive to ensure that it is valid.

unzip -t pimylifeup.zip

Below is an example of what you should see if your zip file is valid with zero errors.

Archive:  pimylifeup.zip
    testing: pimylifeup/              OK
    testing: pimylifeup/howtounzipfiles   OK
    testing: pimylifeup/example.doc   OK
    testing: pimylifeup/ubuntu        OK
    testing: pimylifeup/tutorial.txt   OK
    testing: pimylifeup/pimylifeup.com   OK
    testing: pimylifeup/readme        OK
No errors detected in compressed data of pimylifeup.zip.

Listing the Contents of a Zip Archive

It is also possible to use the unzip command on your Ubuntu system to list the zip archive’s contents.

You could almost see this as the equivalent to using the ls command on your system but specifically for a zip archive.

To list the archive’s contents you need to use the “-l” option alongside unzip.

unzip -l ZIPFILENAME

Make sure you replace “ZIPFILENAME” with the filename you want to get the contents of.

Example of Listing The Contents of an Archive

For our example, let us list the contents of our example archive called “piymlifeup.zip“.

unzip -l pimylifeup.zip

From this command, you should end up seeing a list of all of the files stored within your archive.

Archive:  pimylifeup.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2021-03-04 03:15   pimylifeup/
        0  2021-03-04 03:15   pimylifeup/howtounzipfiles
        0  2021-03-04 03:15   pimylifeup/example.doc
        0  2021-03-04 03:15   pimylifeup/ubuntu
        0  2021-03-04 03:15   pimylifeup/tutorial.txt
        0  2021-03-04 03:15   pimylifeup/pimylifeup.com
        0  2021-03-04 03:15   pimylifeup/readme
---------                     -------
        0                     7 files

Excluding Files when using unzip on Ubuntu

The unzip package includes functionality to exclude files from being extracted from an archive.

To do this, we need to use the “-x” argument to let us list files that we don’t want to be extracted.

This argument also supports wildcards (*) so that you can exclude multiple files with ease.

unzip ZIPFILENAME -x exclude1 exclude2

You can also exclude multiple files by using a space to separate each entry.

Example of Excluding Files

To showcase how this works, we will utilize our trust example archive called “pimylifeup.zip“.

Using this command, we will exclude the files “ubuntu” and “tutorial.txt” from being extracted.

As these files are situated within a directory, we will need to include the directory as part of the filename.

unzip pimylifeup.zip -x pimylifeup/ubuntu pimylifeup/tutorial.txt

You should see your excluded files are not shown when you see the list of files outputted by the unzip command.

Archive:  pimylifeup.zip
   creating: pimylifeup/
 extracting: pimylifeup/howtounzipfiles
 extracting: pimylifeup/example.doc
 extracting: pimylifeup/pimylifeup.com
 extracting: pimylifeup/readme

Unzipping a File using the Ubuntu Desktop Interface

The desktop versions of Ubuntu come with a built-in program called “Archive Manager” or “File Roller“.

You can use this program to extract different types of archives, including Zip files.

By following the next few steps, you will easily unzip your archive files on Ubuntu.

1. On your Ubuntu Desktop device, first browse to where your zip archive is located.

Once located, all you need to do is double-click the file to open it in the archive manager.

To make our example simple, we have our zip archive located on the desktop of our device.

Selecting an archive

2. You should now have your zip file opened in the Archive Manager.

You can use this desktop interface to browse the contents of the archive (1.).

Using this interface, you can click files to choose which ones you want to extract. If you’re going to select multiple files, hold down the CTRL key.

Once you are ready to unzip the archive, click the “Extract” button (2.).

Browsing zip archive contents

3. You can now choose where you want to extract your archived files to.

At the bottom, there are a few options that you can use to choose what files are extracted as well as how the archive manager should handle them.

First, you can choose whether “All files“, “Selected files“, or the specified “Files” are extracted (1.).

Next, you can choose whether you want to keep the current directory structure and whether your archiver shouldn’t overwrite newer files (2.).

Once you are happy with the location and settings you can click the “Extract” button to unzip the archive (3.).

Unzip Archive on Ubuntu

4. Your zip archive should hopefully now be extracted to the location you specified.

You can either choose to close out of the dialog or have it take you to where the archive manager extracted the files.

Successfully Unzipped Files

Conclusion

You should now have learned how you can unzip archives on your Ubuntu-based device.

Unzipping files is a very straightforward process using both the command line or desktop interfaces.

On the desktop interface, you can make use of the inbuilt “Archive Manager” software.

Using the command line, the unzip package makes the process incredibly simple while being very configurable.

If you have had issues with unzipping files on your Ubuntu device, please leave a comment below.

To learn how to use Ubuntu even better, be sure to check out our wide range of guides.

Leave a Reply

Your email address will not be published.