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