Before install Siberian you must Install Zip and Unzip on CentOS
Before you Install Siberian on your server, you must install Zip and Unzip .
A Zip archive is a compressed file format that supports lossless data compression. A zip archive might contain multiple files and directories inside it. Zip is a very popular archive file format.
Every operating system supports zip including all the operating systems by Microsoft as well as all the Linux operating systems.
So now I will show you how to install zip and unzip on Linux operating systems. We will also learn how to zip and unzip files in Linux.
Before we have install Zip and Unzip utilities on our Linux operating system.
Before we move on to the installation part, make sure you have sudo privilege on your Linux server. We need sudo privilege to install new software packages on our server.
So There we go!
Install Zip and Unzip on CentOS
This method will also work for Fedora operating system as both of them use
yum to manage software on the machine. Execute the following commands on your server to install Zip and Unzip on CentOS server.
$ sudo yum update $ sudo yum install zip unzip
Once the process is complete, execute the
zip command to verify the installation. Once the installation is done, we can move on to learn how to zip and unzip in Linux operating systems.
How to Zip in Linux
Zip is a very simple utility. So Let’s see:
$ zip [OPTIONS...] ZIP_FILE_NAME [FILES ...]
Options in zip command allows us to control the execution of the command. Then comes the ZIP_FILE_NAME, we have to replace this with the name of the zip file we want to create, for example,
example.zip. Then, you can list all the files that you want to include in this zip archive.
COMPRESS INDIVIDUAL FILES
We have file1.txt and file2.csv that we want to zip. To compress these files inside a zip archive, we have to run the following command.
$ zip files.zip file1.txt file2.csv
This command will create a zip archive called
files.zip in the current directory.
COMPRESS A DIRECTORY
Now, Let’s say we have a directory called Siberian that we want to compress in a zip archive. To create a zip archive of a directory, we will use the
-r option in zip command. The
-r option will make the process recursive, it means that the zip archive will contain every file and subdirectories contained inside the directory we want to compress.
Here is how we can compress our siberian directory including all the files and directories inside it.
$ zip -r siberian_backup.zip siberian
This command will create a
siberian_backup.zip archive in current directory containing all the files and directories and sub-directories of
COMPRESS EVERYTHING IN CURRENT DIRECTORY
If you want to compress everything in the current directory, navigate to the directory and execute the following command.
$ zip -r backup.zip *
* stands for wildcard character. It means that it will match all the directories and files inside the current directory. Now, Let us see how to password protect our zip archive.
PASSWORD PROTECT A ZIP ARCHIVE
It’s possible also creating password
To create a zip archive of our example siberian directory with password protection, execute the following command.
$ zip -r --password=PASSWORD siberian
This command will create a password protected zip archive containing our example wordpress directory with all the files inside it. It will ask for a password while using the
How to unzip in Linux
Unzip is an utility in linux like zip. Unzip utility allows us to extract files from a zip archive. The simple syntax of unzip command is as follows.
$ unzip [OPTIONS] [ZIP_ARCHIVE] [FILES_TO_PROCESS] [-x FILES_TO_EXCLUDE]
The options allow us to control the execution of the command. After options, we have to specify the name of the zip archive that we want to extract. Then comes the two optional sections in which you can specify the files that you want to process and the files that you want to exclude.
TEST VALIDITY OF ZIP ARCHIVE
We have a zip archive called
siberian.zip that we want to extract. But first, we want to test the zip archive validity. To test the validity of our
siberian.zip archive, execute the following command.
$ unzip -tq siberian.zip
The output of the command should look like the following if the zip archive is valid.
Output: No errors detected in compressed data of siberian.zip.
LIST ALL THE FILES INSIDE ZIP ARCHIVE
If we want to che check all the files in the zip archive we can use the
-l option. So, to get list of all the files and directories inside our zip archive without extracting it, we have to execute the following command.
$ unzip -l siberian.zip
This command will give you the list of every file and directory compressed in the archive. It will also list files inside directories and sub-directories as the function is recursive.
UNZIP A ZIP ARCHIVE
Now, Let’s extract our example
siberian.zip archive. To extract the full archive, execute the following command.
$ unzip siberian.zip
UNZIP A ZIP ARCHIVE EXCEPT FEW FILES
If we want to extract all the files, but we do not want our
wp-config.php file from our siberian backup because we want to create a new file. In that case, we can use
-x option to specify the list of files we want to ignore. To do this, we have to execute the following command.
$ unzip siberian.zip -x wp-config.php
This command will extract all the files from our example wordpress zip archive, except
wp-config.php file. So, this is how we can use the unzip utility to extract zip archives in linux based operating systems. Just like zip and unzip, you can use tar command in linux to extract and compress files in linux.
Zip and Unzip has many more functions that you can use to manage your zip archives.
You can use the
-d option in
unzip command to specify the directory you want to extract from a zip archive. It will only extract the specific directory. Execute
man zip or
man unzip to learn more options provided by zip and unzip respectively