zip
Create compressed archive files
TLDR
Add files/directories to a specific archive
Remove files/directories from a specific archive
Archive files/directories excluding specified ones
Archive files/directories with a specific compression level (0 - the lowest, 9 - the highest)
Create an encrypted archive with a specific password
Archive files/directories to a multi-part split Zip archive (e.g. 3 GB parts)
Print a specific archive contents
SYNOPSIS
zip [options] archive_name [files ...]
PARAMETERS
-r
Recurse into directories. When files are specified, this option will add all files and subdirectories within them.
-u
Update an existing archive. Adds new files and replaces older versions of files already in the archive.
-f
Freshen existing files. Updates only those files that have changed since they were last added to the archive. Does not add new files.
-d
Delete entries from a zip archive. Files specified are removed from the archive.
-m
Move files into zip archive. After successful compression, the original files are deleted.
-0 to -9
Set the compression level. -0 means no compression (store), -9 means best compression. Default is -6.
-e
Encrypt entries in the zip archive using a password. Prompts for a password.
-P password
Use password to encrypt entries. Note: This method is considered insecure.
-j
Junk paths. Store only the name of the saved file, not its full path.
-q
Quiet operation. Suppress most messages, only print errors.
-v
Verbose operation. Print extra information during processing.
-x pattern
Exclude files that match the specified pattern from the archive.
-z
Add a comment to the zip archive. Prompts for the comment text.
DESCRIPTION
The zip command is a powerful and widely used utility for packaging and compressing files into a single archive, commonly known as a zipfile or .zip archive. It is an open-source counterpart to PKZIP, providing cross-platform compatibility across various operating systems, including Linux, macOS, and Windows.
zip can recursively add directories, compress files, update existing archives, and even delete files from them. It employs the DEFLATE compression method by default, balancing compression ratio and speed, but also supports storing files without compression. While primarily a compression tool, it also serves as an archiving utility by bundling multiple files and their directory structure into a single file, making it convenient for distribution, backup, or simply organizing data.
CAVEATS
While zip is excellent for general file compression and archiving, especially for cross-platform compatibility, it has some limitations:
1. Encryption Security: The built-in password protection (standard ZipCrypto) is known to be weak and can often be cracked. For sensitive data, it's recommended to encrypt files using stronger methods (e.g., GnuPG) before zipping them.
2. Metadata Preservation: Unlike tar, zip does not preserve all Unix-specific file attributes (like owner, group, full permissions, hard links, symbolic links) robustly across different operating systems. It primarily focuses on file data and directory structure.
WILDCARD USAGE
When specifying files, shell wildcards like * (matches any sequence of characters) and ? (matches any single character) can be used. It's often crucial to quote these wildcards (e.g., "*.txt") to prevent the shell from expanding them before zip processes them, ensuring zip itself handles the pattern matching correctly, especially with options like -x (exclude).
CROSS-PLATFORM COMPATIBILITY
One of zip's greatest strengths is its widespread support across different operating systems. A .zip archive created on Linux can generally be easily opened and extracted on Windows or macOS systems, and vice versa, making it an excellent choice for sharing files.
HISTORY
The zip file format and its original implementation, PKZIP, were developed by Phil Katz for PKWARE in the late 1980s for MS-DOS. The zip command commonly found on Linux and other Unix-like systems is part of the Info-ZIP project, which began in 1989. Info-ZIP created an open-source, cross-platform compatible suite of utilities (including zip and unzip) that adhered to the zip file format specification, making it a ubiquitous standard for file compression and archiving across diverse computing environments.