How to Unzip a ZIP File in Ubuntu / Linux

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 18.04 or Ubuntu 20.04.

How to unzip a file in Linux 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 yours 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 the terminal. By default, you should start in the /home/user/ directory.

To list the contents of the directory you are 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 looks like this:

Content of Documents folder after unzipping

Note: Observe 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. 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 its contents in the /Documents directory.

Note: 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 existing 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.

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 option with the zip 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 are 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

This article has explained how to unzip and access the content of zip files in Ubuntu Linux.

原创文章,作者:745907710,如若转载,请注明出处:https://blog.ytso.com/224122.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

相关推荐

发表回复

登录后才能评论