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

0 32,315
:2of2
1
2
storage_area_network_with_oracle_zfs_on_centos_linux_l1.jpg | A&H Business Technology
Related posts

Here is how we can compress our wordpress directory including all the files and directories inside it.

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.

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.

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.

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.

The output of the command should look like the following if the zip archive is valid.

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.

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.

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.

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.

Zip and Unzip on Linux
Tar command example on Ubuntu

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.

TinyURL for this post: https://tinyurl.com/y3oe2waf

Sorry, The Comment Form Is Temporarily Closed At This Time
:2of2
1
2
2
You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Language:English