How to Compress Directory with Deflate Zip on Ubuntu
This article provides a concise guide on compressing a directory within the Ubuntu operating system using the zip utility and the deflate algorithm. You will learn the specific terminal commands required to create a compressed archive recursively while maximizing compression efficiency. The steps below ensure your folders are archived correctly for storage or transfer.
Prerequisites
Ensure the zip utility is installed on your Ubuntu
system. Most installations include it by default, but you can install it
using the following command if necessary:
sudo apt update
sudo apt install zipCompression Command
To compress a directory using the deflate method, open your terminal and navigate to the parent folder containing the directory you wish to archive. Execute the following command:
zip -r -9 archive_name.zip directory_nameUnderstanding the Flags
- -r: This flag enables recursive compression, ensuring all files and subdirectories within the target folder are included.
- -9: This sets the compression level to maximum. The zip utility uses the deflate algorithm by default, and this flag optimizes it for the smallest file size.
- archive_name.zip: This is the name of the resulting compressed file.
- directory_name: This is the path or name of the folder you are compressing.
Verifying the Archive
Once the command completes, you can verify the contents and compression method using the unzip utility. Run the following command to list the contents and confirm the deflation method was applied:
unzip -l archive_name.zipThe output will display the file list and the method used, which
should appear as Deflate alongside the compression
percentage.