[フレーム]

Bash zip Command - 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%)


New

W3Schools Adventure App

Coding fundamentals as a game. Bite-sized lessons and challenges.

Ready to start your journey? Your streak is waiting.
+60 XP
W3Schools Adventure tutor
W3Schools Adventure map
×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

FORUM ABOUT ACADEMY
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, cookies and privacy policy.

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

AltStyle によって変換されたページ (->オリジナル) /