How to Extract and Compress ZIP Files on Linux

How to Extract and Compress ZIP Files on Linux Via Terminal

There are many file compression formats supported on Linux, one of which is ZIP. The ZIP file compression format is also used in many other operating systems today, even operating systems mobile. That’s why ZIP is one of the most widely used file compression formats.

In this Learning Terminal tutorial, we will learn how to compress files using the ZIP format, and how to extract compressed files using the ZIP format.

In order to compress and extract files using the ZIP format, you will need a tools named “zip” and “unzip” on Linux. by defaults, on many Linux distributions tools it is installed automatically.

If your device is not installed tools “zip” and “unzip”, you can install them using a command like the following (if you are using a Debian distribution, Ubuntu and down):

sudo apt-get install zip unzip

How to Extract (Unzip) Zip Format Files

Actually, how to extract a compressed file with ZIP format is quite easy, you only need to use the command unzip followed by the name of the file you want to extract in front of it.

For example, if you have a file called “animal.zip” in your home folder, you can extract the file using a command like the following:

unzip hewan.zip

Then the file named “Animal.zip” will be extracted in the folder as shown below:

How to Extract Zip File
How to Extract Zip File

If you want to extract the file to another folder, you can use parameter -d in front of the previous command. For example, if you want to extract the “animal.zip” file to the “Pictures/wallpaper” folder, you can do this by using a command like the following:

unzip hewan.zip -d Pictures/koleksi

Then the contents of the file will be extracted to the “Pictures/collection” folder as shown in the image below:

How to Extract a Zip File to Another Folder
How to Extract a Zip File to Another Folder

In certain cases, when you want to extract a file, you want to see its contents first, you can use parameters -l to see a list of files in the folder as follows:

unzip -l hewan.zip

Then it will appear output the list of files in the “animal.zip” file is as shown in the image below:

How to View the Contents of a Zip File
How to View the Contents of a Zip File

If then you only want to extract only one particular file from the “animal.zip” file, you can do this by adding the name of the file you want to extract as follows:

unzip hewan.zip kucing.png

Then the “kucat.jpg” file (only “kucat.jpg” file) will be extracted from the “animal.zip” file as shown in the image below:

How to Extract Only One Zip File Contents
How to Extract Only One Zip File Contents

How to Compress Files Into Zip Format on Linux

Previously we have learned how to extract a file format “.zip”. This time we will learn the other way around, how to compress files of various formats into “.zip” format.

For example, you have several flower image files in the “flowers” sub-folder in the Pictures folder on your home as follows:

Viewing the Contents of a Folder
Viewing the Contents of a Folder

You can compress these files into a “.zip” file by using the “zip” command followed by the names of the files.

First, go to the “flowers” folder in the “Pictures” folder using the command as below. If you don’t understand how to move folders using Terminal, you can take a look at the Learn Terminal tutorial section 5 on how to enter a folder using Terminal on Linux.

After successfully entering the “flower” folder. Then compress the flower image files using the following command:

zip bunga.zip mawar.jpg melati.jpg kamboja.jpg anggrek.jpg

Then the flower image files will be compressed into a “bunga.zip” file as shown in the following image:

How to Compress Multiple Files Into Zip Format
How to Compress Multiple Files Into Zip Format

You can rename the resulting file (bunga.zip) to whatever name you want. You can also compress an entire folder by using the command zip.

For example, if you want to compress all the files in the previous “flower” folder, you can do this by using the parameter “-r” like the following:

zip -r bunga.zip Pictures/bunga

Then all the contents of the “bunga” folder will be compressed into a “.zip” format file named “bunga.zip” as shown in the image below:

How to Compress Folder to Zip Format
How to Compress Folder to Zip Format

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *