Javatpoint Logo
Javatpoint Logo

How to unzip files in Linux?

Generally, almost all files like documents, media files are shared in the zip format to avoid several types of damages or theft. One can also set the password to protect the files from unnecessary access, which also helps protect the documents' confidentiality. Still, new users or that are not familiar enough with computers or do not have an IT background face many difficulties while working with these types of files, such as opening the zip files, compressing files, etc.

In this tutorial, we will learn how to open the zip files in Linux based operating systems (Ubuntu). Before going further, we need to know how to identify the zip files first. If the downloaded files (or target file) contain .tar.gz or .zip in extension, it means that the file is a type of zip file. To access the contents of a zip file, we need to extract that file, after which we can easily access the content of that file.

The ZIP extension is one of the most used file formats that's utilized for data compression without loss of data. The user can compress multiple compressed files and directories in the ZIP file. So, users require to extract the ZIP files with a few command-line utilities or tools. Users can deal with every type of ZIP file easily with the unzip command in the Linux system.

Prerequisite:

  • Access to the terminal window or command line (Ctrl-Alt-T)
  • Administrator password
  • Zip/unzip utility

Usage of unzip

  • Extracting every compressed file within the current working directory:
  • Decompressing any archive without making directories:
  • Overwriting existing files forcefully during decompression:
  • Decompressing an archive to other directories:
  • See a zip file content without decompressing:
  • Excluding certain when decompressing:
  • List complete information of the archive:
  • Transforming text files during the compression:
  • Showing just a summary message representing whether an archive is fine or not to check our myfile.zip:
  • Showing just the summaries to check every zip file within the current working directory:
  • Extracting every '.txt' text source file:
  • Extracting only newer editions of the files already existed in the current working directory:
  • Extracting only newer editions of the files already existed in the current working directory and making the files not there already:
  • Extracting any password protected zip file:

Options of unzip

Note: The usage screen is restricted to 22 or 23 lines and, therefore, should be taken only as a reminder of the common unzip syntax instead of an exhaustive list of every possible flag to support old hardware.

The exhaustive list pursues:

Option Description
-Z The remaining option is considered to be zipinfo options if -Z is the initial option on the terminal.
-A It prints extended help for the programming interface of DLL.
-c It is used for extracting files to the screen/stdout.
-f Freshen files, i.e., only extracting those files that are already existed on disk and newer than disk copies.
-I It is short for list archive files. The modification times and dates, compressed file sizes, and names of the mentioned files are displayed with totals for every file mentioned.
-p It is used to extract files to stdout (pipe).
-t It is short for the text archive file. It extracts all specified files inside the memory and compares the cyclic redundancy check (or CRC) of the extended file along with the stored CRC value of the original file.
-T On the archive, it sets the timestamp of the newest file.
-u It updates existing files and makes new ones if required.
-v It lists archive files or displays diagnostic version information.
-z It shows the archive comment only.

Modifiers of unzip

Modifiers Description
-a It converts text files. Every file is exactly extracted as they are saved (as binary files).
-b It is used to auto-convert binary files to 512-byte records or fixed-length formats.
-B It saves a backup copy of all overwritten files.
-C It uses a case-sensitive matching method for the archive entry selection from the terminal list of selection patterns.
-D It skips timestamp restoration for extracted items.
-E It shows MacOS extra field contents when restoring the operation.
-F It suppresses NFS filetype extension removal from saved filenames.
-i It ignores filenames saved in MacOS extra fields.
-j It represents junk paths.
-J It represents junk file attributes.
-K It retains Tacky/SGID/SUID file attributes.
-L It converts to lowercase a filename produced on an uppercase-only file system or operating system.
-M It pipes every result from an internal pager which is the same as the Unix command.
-n It never overwrites any existing file.
-N It extracts Amiga filenotes extracted from file comments.
-o It overwrites the existing files without asking.
-P It uses the password to decrypt zip file entries.
-q It quietly performs operations.
-s It converts spaces in underscores in filenames.
-S It converts text files in Stream_LF format rather than the variable-length or text-file default record format.
-U It disables or modifies UTF-8 handling.
-V It retains file versions.
-W It changes the pattern matching routine so both '*' and '?' don't match '/' (directory separator character).

How to install Unzip utility in the Ubuntu?

To unzip a zip archive file, you must have the unzip package installed in your system. However, almost all modern Linux distributions come with unzip support, but there is no harm in verifying it to avoid nasty surprises later in case of you are not sure about it. In Ubuntu and Debian based distributions, one can use the following given steps to install unzip. If it's already installed on your operating system, it will notify you about it.

Step 1: Open the terminal and types the following given command and press enter as shown in the given output:

Command :

Output

How to unzip files in Linux

Once you install the unzip package in your operating system, now you can zip and unzip the files as per requirements.

There are two ways available through which zipped files can be unzipped in the Linux operating system; here, we will discuss both the methods (or processes), along with practical.

Let's understand the above methods in details.

Unzip files using the Linux terminal

The following steps will help us to work with zipped files in Linux and show how to zip files without reducing their quality.

Steps to Unzip files in Linux:

Step 1 - The process of unzipping files in Linux is very straightforward. First of all, open the terminal and go to the directory, where we have our zip file as shown in the given image:

How to unzip files in Linux

Step 2 - Now use the "ls "command to view all files stored in that directory and use the following command to unzip the zip file.

Let's understand the working of this command by following example:

Suppose we have a zipped file such as "samplefile.zip" stored in our download directory. To unzip the "simplefile.zip," we need to open the terminal and go to the download directory using the following commands:

Example

How to unzip files in Linux

Step 2 - Now type the command <unzip "samplefile.zip"> and press enter, and once the file gets unzipped, you can access the content of your unzipped file as shown in the given image:

How to unzip files in Linux

How Zip files in Linux?

The process of converting your standard files into zipped format is slightly different than what we have done earlier. To convert a file (e.g., samplefile.mpg), we have to go to the directory where the file is stored in your operating system. Once you reach the directory, you can use the following command to convert that file into the zipped format.

Command:

To see how this command works, consider the following given example:

How to unzip files in Linux
How to unzip files in Linux

We can also provide the zip file path we want to unzip instead of going to the directory. To do that, consider the following given steps:

Step 1. Open the terminal and type the following given command

Command:

It will show the following output.

In general, this command seems very handy to use. However, in some cases, the user may face a slightly bigger problem while using the above command if he does not use it carefully. The main problem with this command is that it usually extracts all the contents of that particular zip file in the current directory or folder, which is not good, at least in some cases.

Unzip files to the Directory

The above problem can be avoided easily by unzipping the target file to an individual directory instead of extracting it into the current directory. This way, our all extracted files will be stored in the specified directory. In some situations where the directory specified by the user does not exist, it will also take care of that by creating the directory with the mentioned label.

Let see how to unzip a file to a particular directory

To unzip a zipped file to a particular folder or directory, one can use the following instructions:

Step1: Open the terminal and go the directory where your compressed or zipped file is stored. Once you reach that directory, type the following given command in the terminal

Command :

To understand how this command works, consider the following given example:

Suppose you have a zipped file (e.g., samplefile.zip ) that you want to extract in a particular different directory (e.g., Akash).To do that, you need to specify the directory or address of the directory in which you want to extract your zipped file. Hence our command will be looks like the following ones:

Command

<unzip samplefile.zip -d \Akash>

Output

How to unzip files in Linux

Now all the content of the samplefile.zip will be extracted to the user's specified directory.

2. Unzip files via the Graphic User Interface:

This method is absolutely simple for all users, even for beginners. It just looks like that of the window's process of extracting zip files. To unzip the zip files via the graphic user interface, follow the instructions given below.

Step 1. Open the file explorer in your Linux operating system:

How to unzip files in Linux

Step 2. Now go to that folder, where you stored zipfile (e.g., textfile.zip) and select it, as shown below:

How to unzip files in Linux

Step 3. After selecting the zipped file, click the mouse's right button to view more options:

How to unzip files in Linux

Step 2. Now click on the option "Extract Here" or "Extract to" as per requirements. We want to extract that file in the current folder, then click on the "Extract" option.

How to unzip files in Linux

Step 4. In case you want to extract that file in a different folder, then you can use the "Extract to" option as shown below:

How to unzip files in Linux

Step.5 After clicking on the "Extract to" option, a new window will be opened in which you have to specify any directory where you want to store the content of the file. Once you select the directory or folder, click on the Select option as shown below:

How to unzip files in Linux

Step5. Now we move to the selected folder or directory to verify that file is unzipped.

How to unzip files in Linux
Next Topicchroot Command





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA