Working with zip
in Linux
zip
is a popular compression and archive format.- Bundles and compresses files/directories into a single
.zip
file. - Compatible across different operating systems (Linux, Windows, macOS).
Install zip
and unzip
sudo apt install zip unzip # Debian/Ubuntu
sudo yum install zip unzip # RHEL/CentOS
Syntax
zip [options] archive_name.zip files/directories
Create a Zip Archive
zip archive.zip file1.txt file2.txt
- Compresses files into
archive.zip
zip -r archive.zip folder/
-r
: Recursively zip all files and subfolders infolder/
Add Files to Existing Archive
zip archive.zip newfile.txt
Exclude Files While Zipping
zip -r archive.zip folder/ -x "*.log"
- Excludes all
.log
files
Working with unzip
in Linux
Syntax
unzip [options] archive_name.zip
Extract a Zip Archive
unzip archive.zip
- Extracts into the current directory
Extract to a Specific Directory
unzip archive.zip -d /path/to/target/
List Contents Without Extracting
unzip -l archive.zip
Overwrite or Skip Existing Files
unzip -o archive.zip # Overwrite without prompting
unzip -n archive.zip # Never overwrite
Password-Protected Archives
Create a Password-Protected Zip
zip -e archive.zip file1.txt
- Prompts for password
Extract a Password-Protected Zip
unzip archive.zip
- Prompts for password if required
Summary Table
Task | Command |
---|---|
Create zip file | zip archive.zip file1.txt |
Zip directory recursively | zip -r archive.zip folder/ |
Extract zip file | unzip archive.zip |
Extract to folder | unzip archive.zip -d /target/folder |
List contents | unzip -l archive.zip |
Create password-protected | zip -e archive.zip file1.txt |
Exclude files | zip -r archive.zip folder/ -x "*.tmp" |
Last updated on