Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH

Bash zip - Package and compress (archive) files

Using the zip Command

The zip command is used to package and compress files into a ZIP archive.


Basic Usage

To create a ZIP archive, use zip archive.zip file1 file2:

Example

zip archive.zip file1 file2
adding: file1 (stored 0%)
adding: file2 (stored 0%)

ZIP Options Overview

Here are some common options you can use with the zip command:

  • -r - Recursively zip directories
  • -u - Update files in the archive if they are newer
  • -d - Delete files from the archive
  • -e - Encrypt the contents of the ZIP archive
  • -x - Exclude specific files from being zipped

Option: -r (Recursive)

The -r option allows you to zip directories and their contents recursively.

Example: Recursive Zip

zip -r archive.zip folder/
adding: folder/ (stored 0%)
adding: folder/file1 (stored 0%)
adding: folder/file2 (stored 0%)
adding: folder/subfolder/ (stored 0%)
adding: folder/subfolder/file3 (stored 0%)

Option: -u (Update)

The -u option updates files in the archive only if they are newer than the existing files.

Example: Update Archive

zip -u archive.zip file1 file2
updating: file1 (deflated 60%)
updating: file2 (deflated 60%)

Option: -d (Delete)

The -d option deletes specified files from the archive.

Example: Delete from Archive

zip -d archive.zip file1
deleting: file1

Option: -e (Encrypt)

The -e option encrypts the contents of the ZIP archive, requiring a password to unzip.

Example: Encrypt Archive

zip -e archive.zip file1 file2
Enter password:
Verify password:

Option: -x (Exclude)

The -x option excludes specific files from being added to the archive.

Example: Exclude Files

zip archive.zip file1 file2 -x file2
adding: file1 (stored 0%)


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.