✅ How to Zip and Unzip Files & Folders in Linux/Ubuntu (Full Guide with Examples)
Compressing and extracting files is one of the most common tasks in Linux. Whether you want to reduce file size, transfer multiple files easily, or secure your data with a password, Linux provides powerful tools to Zip and UnZip files.
In this complete guide, you’ll learn:
✔ What ZIP files are
✔ How to install zip/unzip tools
✔ How to zip files & folders
✔ How to unzip safely
✔ Password-protecting archives
✔ Excluding files
✔ Overwriting behavior
✔ Listing ZIP content
✔ Practical examples
⭐ What is a ZIP File?
A ZIP file is a compressed archive that contains one or more files or folders.
Benefits:
-
✔ Reduced file size
-
✔ Easy to share multiple files
-
✔ Supports password protection
-
✔ Can split files into smaller parts
-
✔ Lossless compression
Linux uses zip to compress and unzip to extract files.
🟩 Installing Zip and Unzip in Linux
Most Linux distributions do not come with zip/unzip installed. Install them using:
Install on Ubuntu/Debian
Install on CentOS/Fedora/RHEL
🟦 How to Zip Files and Folders in Linux
Let’s learn how to CREATE zip files first.
1️⃣ Zip a Single File
2️⃣ Zip Multiple Files
3️⃣ Zip a Folder
-r means recursive → includes all files & sub-folders.
4️⃣ Create a ZIP with Password
This command will prompt for a password.
5️⃣ Exclude Files While Zipping
6️⃣ Zip with Maximum Compression
🟥 How to Unzip (Extract) ZIP Files in Linux
Now let’s extract ZIP files using the unzip command.
1️⃣ Unzip to Current Directory
You must have write permission in the directory.
2️⃣ Suppress Output (Silent Mode)
3️⃣ Unzip to a Different Directory
Example:
Note: Using sudo makes extracted files owned by root.
4️⃣ Unzip a Password Protected ZIP
✔ Using password in command:
⚠ Not recommended — password is visible.
✔ More secure method:
It will ask for a password:
5️⃣ Exclude Files When Unzipping
6️⃣ Overwrite Files Automatically
⚠ This overwrites existing files without warning.
7️⃣ Unzip Without Overwriting (Skip Existing Files)
Useful when:
-
You modified some files
-
You want to restore deleted files only
8️⃣ Unzip Multiple ZIP Files at Once
✔ Use single quotes → prevents shell expansion.
9️⃣ List the Contents of a ZIP File
Example output:
🔵 Useful Zip & Unzip Tips
✔ Test ZIP File Integrity
✔ Extract Only Specific File
✔ Extract to stdout (show file content)
🟣 Conclusion
ZIP files are an efficient way to compress, secure, and transfer files on Linux.
Using the zip and unzip commands, you can:
-
Create ZIP archives
-
Extract files safely
-
Protect ZIPs with passwords
-
Exclude or overwrite files
-
List ZIP contents
-
Extract anywhere
Linux provides full control and flexibility over compression tools.
