How to ZIP a Folder in Linux
If you are a Linux user, then you know that compressing files into archive formats is a common task. Among all the compression formats, ZIP is one of the most popular formats out there. It is widely supported by Windows, macOS, and Linux platforms. In this article, we will explain how to ZIP a folder in Linux.
Before we begin, you might have noticed that your Linux distribution already comes with a graphical archive manager. However, in this tutorial, we will focus on the command line method as it is faster, efficient and requires no additional software installation. So, let’s dive in.
Step 1: Open Your Terminal
The first thing you need to do is to open the terminal. You can open the terminal in a variety of ways, depending on your Linux distribution.
For example, on Ubuntu, you can press ‘Ctrl + Alt + T’ on your keyboard to open the terminal. On Fedora, you can click on the ‘Activities’ menu, type ‘Terminal’ in the search box, and then click on the Terminal icon that appears.
Alternatively, you can also find it by navigating to the Applications menu, then Accessories and select Terminal.
Step 2: Navigate to the Folder that You Want to Compress
Once you have opened the terminal, you need to navigate to the folder that you want to compress. You can use the ‘cd’ (Change Directory) command to enter the folder. For example, if you want to compress the ‘Documents’ folder on your Desktop, use the following command:
cd ~/Desktop/Documents
Make sure to replace ‘Documents’ with the name of the folder you want to compress.
Step 3: Compress the Folder using ZIP Command
Now that you have navigated to the folder that you want to compress, the next step is to use the ‘zip’ command to create a compressed ZIP archive.
The syntax of the ‘zip’ command is as follows:
zip [options] archive_name.zip file_name(s) […]
In other words, you need to specify the name of the ZIP archive that you want to create, followed by the name of the folder that you want to compress.
For example, if you want to compress a folder named ‘Documents’ and create a ZIP archive named ‘Documents.zip,’ use the following command:
zip -r Documents.zip Documents/
The ‘r’ option tells the ‘zip’ command to compress the folder recursively. This means that all subfolders and files inside the ‘Documents’ folder will also be included in the ZIP archive.
Step 4: Verify the Compressed ZIP Archive
After you have compressed the folder into a ZIP archive, you should verify the compressed archive to ensure that it is valid and free of errors. The ‘unzip’ command comes pre-installed on most Linux distributions and can be used to verify the compressed ZIP archive.
Here is a command you can use to verify the compressed ZIP archive:
unzip -t Documents.zip
This command will test the integrity of the ZIP archive and display a list of files that have been compressed into the archive.
And that’s all there is to it.