bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Bash/File Compression
Bash•File Compression

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%)

Chapter

Back to File Compression

Next

Bash unzip Command - Extract from ZIP archive

This chapter

Overview
3

Lessons

6m

Read time

1. Bash zip Command - Package and compress (archive) files2. Bash unzip Command - Extract from ZIP archive3. Bash tar Command - An archiving utility

On this page

Using the zip CommandBasic UsageZIP Options OverviewOption: -r (Recursive)Example: Recursive ZipOption: -u (Update)Example: Update ArchiveOption: -d (Delete)Example: Delete from ArchiveOption: -e (Encrypt)Example: Encrypt ArchiveOption: -x (Exclude)Example: Exclude Files