How to Zip and Unzip Files in CentOS 7

Zipping and unzipping files is not as simple of a task in Linux as it is in Windows OS. It requires a bit more knowledge and experience as well as knowing some basic commands. Today we will show you how to zip and unzip files in CentOS 7.

Updated: 05 Mar, 23 by Antoniy Yushkevych 6 Min

List of content you will read in this article:

There are many situations when we want to compress the files and store them on the system to save some space. The zip comes as a file compression utility that has been used on every operating system. It comes as a default utility for compressing files readily available on Windows operating system, Mac OS, and Linux OS. You can use all the compressed files as zip files. Also, if you create a zip file on one system, you can use these zipped files on another operating system without any compatibility issue due to the underlying operating system.

Here, we are using the Linux distribution, CentOS that uses the unzip command for opening the zipped files. In this article, we will learn how to play around with the unzip command on the CentOS 7 system.

By default, there is no unzip package available on CentOS 7 system. But you can get it from the official package repository of the CenOS 7 operating system. So there is no problem with installing this package. To start the installation, first, you have to update the yum package repository cache by running the following command.

$ sudo yum make_cache

After this, you will get the updated YUM package repository cache as shown below.

After that, you can start installing the unzip package using the following command:

$ sudo yum install unzip

Then, you need to press the “y” and then hit <Enter> to continue.

This will definitely install the unzip package.

If you want to check if the unzip is working properly, then you can run the following command.

$ unzip -v

In the following image, you can see that the unzip utility is working properly.

If you are working with a graphical desktop environment like GNOME desktop, then you can easily use the zip files.

As you can see, below we have an file at the path ~/Downloads under the HOME directory.

When you right-click the zipped folder, then you will get various options mentioned below. Also, you will see the “open with archive manager” option. Once you double-click the zip file, by default it will get opened by the achieve manager. 

Alternatively, you can also select the Extract Here to extract the zip file options as shown below.

Now, you can see that the zipped folder is being opened in the archive manager where you can see the list of contents of the zip file.

At the top of the archive manager, you will get the extract option. After clicking the extract option available at the top, you can see the content of the zip file has been extracted.

After that, you will be taken to the below window for extracting the zip file. From here, you can click the extract option on the top-right corner for extracting the zip file in the current directory. For extracting the zip file’s content to a new or another folder, you need to create a new folder accordingly.

Here, we have first created a new directory name as myapp/ as shown below and then we have started the extraction of the contents of the Zip file there.

Now, the contents of the Zip file are completely and successfully extracted into the myapp/ directory.

If you want, you can choose a specific file and folder from the Archive Manager and use its drag and drop functionality to place them in a directory. Only your required files and folders will get extracted.

If you want to list all the contents of the files and directories present within the zip file, you can use the following command.

$ unzip -l

Now in the following image, you will get all the contents of the Zip archive

For extracting the zip file, you can easily use the unzip command. But, in order to extract a zip file in the current directory containing the zip file, then you can use the following mentioned command

$ unzip

Once you run the above-mentioned command, you will get all the contents of the Zip file extracted to your current working directory.

According to the above image, all the files and directories will get extracted in the same path. Now we have seen the command format for extracting the zip file into the same directory, but for extracting the zip file’s content to another specified directory, then you can use the following command. But before that you have to make sure that you create the specified directory if it does not exist beforehand, running the command.

$ mkdir ~/Downloads/myapp

After you run the above command in order to create the directory, you can run the following command for extracting the Zip file into the ~/Downloads/myapp directory:

$ unzip -d ~/Downloads/myapp

The complete content present within the file will get extracted into the ~/Downloads/myapp directory as you can see in the screenshot below.

If you want to extract the specific files and directories from the zip file, then you can do it using the unzip command. Suppose, you want to extract only the server,js file from the zip file, then you can use the following command format.

$ unzip server.js

This format will ensure that only the server.js will be extracted.

Also, you can even specify the specified directory where you want to extract the files and directories, using the following command.

$ unzip server.js -d ~/Downloads/myapp

If you want to extract a specific subdirectory from the Zip file, you can run the following command.

$ unzip 'models/*' -d ~/Downloads/mypp

Zip and unzip commands are very important when you are considering saving space even during the transmission of files from one system to another or via email. Linux distribution, CentOS 7 comes with the special command unzip for extracting the zipped file. You can use various command formats for specific purposes.

You can go through this guide to get along with the unzip command on CentOS 7.

People Are Also Reading:

Antoniy Yushkevych

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at
user monovm

3up computer

2021, Sep, 21

nice information.... thanks