The ZIP format in a file is known as an archive file which is used to store various files into one. Besides ZIP, there are also RAR, TAR, GZ, and many more. It’s just that most people are more familiar with this ZIP format.
Creating a ZIP file on Linux can be done quickly via the terminal. Not only making it, but extracting it can also be done quickly by typing commands. And this article will show you the tutorial.
Install ZIP and UNZIP on Linux
The process of installing it is very easy and can be done through the Terminal. Please use the command below according to OS used now.
Ubuntu and Debian
sudo apt-get install zip unzip -y
CentOS, Fedora, and Redhat
sudo yum install zip unzip -y
zypper install zip unzip -y
It only takes a few seconds, package ZIP and UNZIP has been successfully installed and ready to use. Now you can start to try to archive several files or folders into one.
Creating ZIP Files on Linux
For example, here I want to compress two files named example1.txt and example2.txt. Here is the command:
zip hasil.zip contoh1.txt contoh2.txt
So later will be created a file named result.zip which in it are the two examples of file names above.
Archive All Files in a Folder
If the example above was only for archiving files, but there is a little extra if you want to archive the folder and the files in it. That is, only need to add commands or attributes -r.
For example here I want to archive a folder named HTTPCS and all of its contents. Here is the command:
zip -r hasil.zip HTDOCS
Create ZIP File with Password
It only takes a few more attributes to be able to add a password to the ZIP file that will be created, here is an example of the command.
zip -p KataSandi hasil.zip contoh.txt
Text Password The above is just an example, please change it according to the password you want to use.
Also read: How to Create a TAR.GZ File on Windows
Extracting ZIP Files on Linux
It’s actually as easy as making it. To extract or extract the ZIP file, you can use the UNZIP command as below:
For the example above you will extract a file named file.zip. And all the files in it will be issued in the directory you are currently using.
Extracting In Specific Directories
Just add attributes -d in the command to start setting the directory where the extracted ZIP file is located. For example here I want to output it to a directory /home/users/.
unzip berkas.zip -d /home/user/
Using UNZIP with Password
Sometimes a private file has to enter a password to be extracted. And the procedure is the same as the process of making it, where you only need to add attributes -p to write down the password.
unzip -p KataSandi berkas.zip
By now, of course, you already understand about creating ZIP files and extracting them. The command is very simple isn’t it? Even doing it from the Terminal is no less fast than GUI.
The process of creating or extracting the ZIP file will be displayed on the screen. Make sure you wait until the process stops / finishes so that later the archive doesn’t corrupt. If you have any questions regarding the tutorial above, you are very welcome to comment below.
Hopefully useful and good luck