Working with zip in Linux
zipis a popular compression and archive format.- Bundles and compresses files/directories into a single
.zipfile. - 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/CentOSSyntax
zip [options] archive_name.zip files/directoriesCreate 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.txtExclude Files While Zipping
zip -r archive.zip folder/ -x "*.log"- Excludes all
.logfiles
Working with unzip in Linux
Syntax
unzip [options] archive_name.zipExtract 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.zipOverwrite or Skip Existing Files
unzip -o archive.zip # Overwrite without prompting
unzip -n archive.zip # Never overwritePassword-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