How to Unzip a File in Ubuntu

By
Vladimir Kaplarevic
Published:
March 25, 2024
Topics:

Introduction

Knowing how to unzip a file in Ubuntu allows you to access and use compressed files, saves storage space, and makes transferring and sharing files easier.

Moreover, many software packages are distributed in compressed formats, so being able to unzip files is essential for software installation and system maintenance.

This guide explains how to unzip a file in Ubuntu using one of the two methods.

How to Unzip a File in Ubuntu

Prerequisites

How to Unzip a ZIP File in Ubuntu

There are two ways to unzip a file in Ubuntu: via the unzip command or GUI (Graphical User Interface). The following text elaborates on both methods.

Unzipping a File in Ubuntu via the unzip Command

The unzip command provides control and flexibility over file extraction. It also allows for the efficient extraction of multiple files simultaneously, making it more suitable for batch operations than a graphical user interface (GUI).

To extract files using unzip, follow these steps.

1. Ubuntu distributions usually include the unzip utility by default. If your machine does not, update the repositories with sudo apt update and use the following command to install unzip:

sudo apt install unzip
sudo apt install unzip

2. Locate the file you want to unzip. In this example, the files.zip archive is located in the Home directory. To verify the file is there, run the ls command:

ls
ls terminal output

The archive (colored red) is present in the current directory.

Note: In case your archive is not in the current directory, navigate to its location using the cd command.

3. To unzip the files.zip archive, run the following:

unzip files.zip
unzip terminal output

The system decompresses the file and places a copy of its contents in the current directory.

Unzipping a File in Ubuntu Using the GUI

Another way to unzip an archive is using GUI. For instance, to unzip the files.zip archive, follow these steps:

1. Right-click the archive.

Right-clicking an archive in Ubuntu

2. Choose Extract Here.

Extracting an archive in Ubuntu via the GUI

3. Check the current directory to verify the process was successful. The extracted files are placed in the directory with the same name as the archive.

Files extracted

To extract files to a different directory:

1. Choose Extract to... after right-clicking the archive.

Extract files to a different directory

2. Navigate to the location where you want to extract the files. In this example, it's Documents.

Navigate to the location where you want to extract files

3. Click Select.

Click Select button

4. Access the selected directory (in this case, Documents) to confirm files are extracted there.

Confirm files are extracted

unzip Command Additional Options and Examples

The unzip command also works with additional options, which provide more control over how it works. The common options are in the table below.

OptionDescription
-P Specifies a password for ZIP archives.
-tTests if the file is valid.
-jExtracts files without creating directories for them.
-xExcludes a file when unzipping.
-qQuiet mode. Suppresses the normal output unzip output.
-vVerbose mode. Displays detailed information about the extraction process.
-lLists the ZIP file contents.
-dExtracts the file contents to a different directory.
-oOverwrites files without prompting.

The following sections show usage examples of different unzip options.

How to Test a ZIP File is Valid

If you think the zipped file has been damaged or corrupted, use the โ€“t option to test the file. Run the following:

unzip -t [zip-file-name]

In this example, we're testing the files.zip file with:

unzip -t files.zip
Terminal output for unzip -t

The output confirms the ZIP archive and its contents are intact and without errors.

How to Exclude Files When Unzipping a ZIP File

To exclude a file when extracting files, run the following:

unzip [zip-file-name] โ€“x [file-name]

For instance, files.zip contains two files: File1 and File2. To exclude File1 from being extracted, run:

unzip files.zip -x File1
unzip -x terminal output

The command only extracts File2.

How to List the Contents of a Zip File

To list ZIP file contents, use the -l option with the zip command. For instance, list files.zip contents with:

unzip -l files.zip
unzip -l terminal output

Extract a ZIP File to a Different Directory

To specify you want to unzip to a different destination than the directory you are in, type the command:

unzip [zip-file-name] โ€“d [destination-directory-name]

For instance, unzip files.zip to the Documents directory with:

sudo unzip files.zip -d /Documents
sudo unzip -d terminal output

In this example, using the sudo command is necessary because the extraction destination directory /Documents requires administrative privileges.

How to Unzip Multiple ZIP Files

For example, the current directory contains several zipped archives (files, files1, files2).

terminal output for ls

To unzip all the archives in the current directory, run:

unzip "*.zip"
unzip all archives

The * sign is a wildcard, which means any number of characters. Therefore, the command finds and unzips any file that ends in .zip.

Conclusion

This article explained how to unzip a ZIP file in Ubuntu via the terminal or GUI. Refer to the provided examples to test how the command works.

Next, learn how to zip a file in Linux.

Was this article helpful?
YesNo