QUICK TIP - Zip and Unzip on Linux with 2 easy WordPress Examples

- 1. QUICK TIP - How to make a YouTube subscription link and get more subscribers
- 2. QUICK TIP - Create Password Protected PDF with PHP & MySQL
Here is how we can compress our wordpress
directory including all the files and directories inside it.
1 |
$ zip -r wordpress_backup.zip wordpress |
This command will create a wordpress_backup.zip
archive in current directory containing all the files and directories and sub-directories of wordpress
directory.
COMPRESS EVERYTHING IN CURRENT DIRECTORY
If you want to compress everything in the current directory, navigate to the directory and execute the following command.
1 |
$ zip -r backup.zip * |
The *
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
Zip also allows you to password protect a zip archive. However, this feature is not recommended because the password we will pass while executing the command will be in a plain text format.
It is good only if no one is looking over your shoulder. To create a zip archive of our example wordpress
directory with password protection, execute the following command.
1 |
$ zip -r --password=PASSWORD wordpress |
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 unzip
utility.
How to unzip on 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.
1 |
$ 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
For example, Let’s say we have a zip archive called wordpress.zip
that we want to extract. But first, we want to test the zip archive validity.
To test the validity of our wordpress.zip
archive, execute the following command. These commands will help you how to Zip and Unzip on Linux step-by-step.
1 |
$ unzip -tq wordpress.zip |
The output of the command should look like the following if the zip archive is valid.
1 2 |
Output: No errors detected in compressed data of wordpress.zip. |
LIST ALL THE FILES INSIDE ZIP ARCHIVE
Now, to take a look at all the files inside 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.
1 |
$ unzip -l wordpress.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 wordpress.zip
archive. To extract the full archive, execute the following command.
1 |
$ unzip wordpress.zip |
Yes, simple! Done and you definitely know how to Zip and Unzip on Linux.
UNZIP A ZIP ARCHIVE EXCEPT FEW FILES
Now, Let’s say we want to extract all the files, but we do not want our wp-config.php
file from our WordPress 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.
1 |
$ unzip wordpress.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 on Linux, you can use tar command in Linux to extract and compress files in Linux.

Conclusion
Zip and Unzip on Linux has many more functions that you can use to manage your zip archives. For example, 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 on Linux respectively.
Furthermore, you already know how to customise the command of Zip and Unzip on Linux to except some files that you do not want to execute.
Besides, I added some useful Bash Script tutorials related to Linux commands.
If you are stuck somewhere in the process, please let us know in the comment section given below. We will respond as soon as possible with the solution.