Skip to Content
This project is a work in progress. If you have any questions or suggestions, feel free to contact me.

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 in folder/

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

TaskCommand
Create zip filezip archive.zip file1.txt
Zip directory recursivelyzip -r archive.zip folder/
Extract zip fileunzip archive.zip
Extract to folderunzip archive.zip -d /target/folder
List contentsunzip -l archive.zip
Create password-protectedzip -e archive.zip file1.txt
Exclude fileszip -r archive.zip folder/ -x "*.tmp"
Last updated on