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] zipfile [list of files]
PARAMETERS
-r
Recursively compress directories. This option is essential for including entire directory trees in the zip archive.
-e
Encrypt the zip archive using a password. This adds a layer of security to protect the contents of the archive.
-P password
Provide a password on the command line (less secure than using -e, as it's visible in the shell history).
-q
Quiet mode; suppress normal output messages.
-9
Best compression (slowest).
-0
Store only; no compression.
-j
Junk pathnames; store just the file names (not the directory structure).
-x list
Exclude files or directories specified in the list. List is comma separated.
DESCRIPTION
The zip command is a widely used utility in Linux for creating zip archives. It allows you to compress one or more files and directories into a single file with a `.zip` extension. This compressed archive can then be easily shared, stored, or transferred. zip employs various compression algorithms (most commonly DEFLATE) to reduce the size of the original data. It supports encryption to protect sensitive data within the archive, and can also be used to update existing zip archives by adding, deleting, or modifying files. It is compatible with zip archive formats widely supported across different operating systems.
zip offers various options to control the compression level, manage directory structures, handle symbolic links, and exclude specific files or directories from the archive. Its versatility and ease of use make it an essential tool for managing files and archives on Linux systems.
CAVEATS
Using the `-P` option to specify a password directly on the command line is strongly discouraged because the password will be visible in the shell history and potentially exposed to other users on the system. The zip command does not handle symbolic links perfectly in all circumstances. Test the extraction to see the result. Consider using tar to archive with symlinks.
EXIT CODES
The zip command returns various exit codes to indicate the success or failure of the operation. An exit code of 0 typically indicates success, while non-zero exit codes indicate different types of errors.
Common Exit Codes:
0: Normal exit.
2: Unexpected end of archive.
9: Command line error.
12: Could not create output file.
HISTORY
The zip command has a long history dating back to the early days of computing. It was initially created to address the need for a standard archive format that could be used across different platforms. The ZIP file format was developed by Phil Katz of PKWARE in the late 1980s and early 1990s. The zip command itself has been implemented in various forms and has become a standard tool for archiving and compressing files in many operating systems, including Linux, Windows, and macOS.