How to Compress Files Using the Zip Command on Linux

Understanding the Benefit of Zipping Files

Compressing or zipping files provides an efficient solution for storing backups of original files. This process also enables the grouping of multiple files into a single file of reduced size for easier storage and accessibility.

Initiating the Zip Process

To compress a single file, you can apply a specific command. The following example illustrates such a command for a file named ‘tips.html’.

File Size After Compression

Post compression, you will note the file size has reduced by 73%. Comparing it with the original file size will validate that the zipped file is indeed significantly smaller. The absence of the “zip” file extension when creating the compressed file won’t impact the process as the system automatically appends it.

Preservation of the Original File

Importantly, compressing a file or creating a zipped version does not eliminate the original file from the system.

You can compress a series of files into a single zip file as a backup solution using a compacted format. Be advised that while compressing the files, the compression ratio is indicated for each file.

If you prefer to zip the files without the specifications of each file appearing, you may utilize the -q argument.

It’s essential to note that if the directory you’re zipping includes subdirectories, those subdirectories will be compressed into the zip file but not their contents. That is unless you apply the -r (recursive) argument. Here’s an example:

This example demonstrates the usage of -r, which subsequently includes the files in the NOTES subdirectory in the bin.zip archive it is generating.

To initiate the process of adding a password which would be required to unlock the contents of a zip file, the below-shown command can be used. For confirmation, it would prompt the entry of password twice albeit it does not display the password onscreen.

The command for extracting the contents packed in a zip file is the unzip command. As shown in the example below, since a password was used to encrypt the zip file, that password must be provided for successful decryption and extraction of the contents.

Interestingly, if the goal is to unpack the contents of a zip file into a distinct directory, there’s no need to cd command into the directory. Rather, you may append the -d option along with the target directory to specify the new destination.

If the requirement is to extract a solitary file from the zip file, all that’s needed is to state its name as recorded in the zip file. Here’s a demo command where the primary file (perhaps it’s been compromised in certain manner) is substituted after acquiring the confirmation that it’s indeed what you want.

Your original code doesn’t need to be changed as it already adheres to the instructions provided. The HTML code remains the same as your code doesn’t contain any of the elements (iframe, embed, form, img, style, noscript) that need removal. It also does not include any id, class, style, width, or height attributes.

Here is your original code:

Zipping files to preserve them, back them up, extract them and require passwords for extraction are all important things to know when dealing with the zip command.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Article

Why Generative AI Doesn't Simplify Hardware Challenges

Next Article

A Plea to Our Tech Overlords: It's Time to Watch the Whole Movie

Related Posts