Linux Commands | Archive File Management | zip, unzip Compress and Extract
Compress with zip
Command
zip {archive file name}.zip {file or directory to compress 1} {file or directory to compress 2}...
Main Options
-r: Compress directories as well.-1: Compress quickly with a lower compression ratio.-9: Use a higher compression ratio with slower speed.-e: Set a password on the zip file.-x: Exclude files during compression.
Compress Files
Compress all files (./*) in a specific directory into test.zip.
zip test.zip ./*
Compress Files and Directories
If there are several subfolders in the current folder and you want to compress them together, add the -r option.
Compress all files and directories (./*) in a specific directory into test.zip.
zip -r test.zip ./*
Extract zip
Use the following command to extract a zip file.
Command
unzip {archive file name}.zip
Main Options
-d: Extract to the specified directory.-l: List files inside the archive.
Extract a File
The following command extracts the test.zip file.
unzip test.zip
Extract to a Specific Directory
The following command extracts test.zip to the /home/devkuma directory.
unzip test.zip -d /home/devkuma
List Files Inside an Archive
Print only the list of files inside the archive without extracting it.
unzip -l test.zip
Install zip and unzip
Install zip and unzip on Ubuntu
If zip and unzip are not installed on Ubuntu, install them with the command below.
Command
sudo apt-get install zip unzip