Linux zip Command: Create ZIP Archives

zip bundles and compresses files and directories into a single ZIP archive. It is a format often used when exchanging files with other operating systems.

What is the zip command?

The first argument is the ZIP file to create or update, and the following arguments are the files to include. To include files inside directories, specify -r. When running on an existing ZIP file, it does not necessarily create a new archive from scratch, but can update or add existing entries, so confirm your intended action first.

Basic syntax

zip [options] archive.zip file or directory...

Installed implementations and options may vary depending on the distribution. Check your current system's description with man zip.

Examples

Bundling two files

Choose a new ZIP name that does not already exist.

zip documents.zip report.txt notes.txt

Compressing an entire directory

Include subdirectories and files with -r.

zip -r project.zip project/

Check the created archive

After compression, review the file list with unzip -l.

unzip -l project.zip

Checking what is in a ZIP file

zip can put multiple files into a single ZIP archive. -q performs the addition quietly, and listing is done with a separate command.

printf 'hello\n' > note.txt
zip -q bundle.zip note.txt
unzip -Z -1 bundle.zip

Example output:

note.txt

Just because a name appears in the list doesn't mean the integrity of the archive is verified. You can check the structure with unzip -t bundle.zip. The default encryption of a password-protected ZIP may not be sufficient to protect sensitive information, so if security is the goal, choose an appropriate encryption method separately.

Main Options and Format

Options/Format Description
-r Include the subitems of directories recursively.
-0 Store files without compression.
-1 ... -9 Select the compression level.
-u Update changed files in an existing archive.
-x pattern Exclude matching paths.

Precautions when using

When reusing an existing ZIP file, the configuration content may be updated differently than expected, so either create it with a new name or make a backup first. Do not assume common ZIP password options provide strong security; choose appropriate encryption tools for sensitive data. The ZIP format may not preserve metadata such as permissions and ownership consistently across platforms.

Frequently Asked Questions

Does using `zip project.zip project/` include all the files in the folder?

No. To include the contents of the directory recursively, you usually use `zip -r project.zip project/`.

Official Documentation

You can check the exact behavior of the options and implementation-specific differences in the official documentation for zip.

More in This Category
Linux Tutorial / Understand Users, Groups, and File Ownership

Linux Tutorial / Understand Users, Groups, and File Ownership

Understand UIDs, GIDs, primary and supplementary groups, and file ownership, then inspect them safely with id, groups, getent, ls, and stat.

Linux tar Command: Create and Extract Archives

Linux tar Command: Create and Extract Archives

Learn how to create and Extract Archives with the Linux tar command, including practical examples, key options, and important precautions.

Linux tree Command: Display a Directory Tree

Linux tree Command: Display a Directory Tree

Learn how to use the Linux tree command to display directory contents as a readable hierarchy and control depth and filtering, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux chmod Command: Change File and Directory Permissions

Linux chmod Command: Change File and Directory Permissions

Learn how to change File and Directory Permissions with the Linux chmod command, including practical examples, key options, and important precautions.

Linux host Command: Look Up DNS Names and Addresses

Linux host Command: Look Up DNS Names and Addresses

Learn how to look Up DNS Names and Addresses with the Linux host command, including practical examples, key options, and important precautions.

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Learn how to inspect and Configure Network Interfaces and Routes with the Linux ip command, including practical examples, key options, and important precautions.

Linux apt-get Command: Run APT Package Operations in Scripts

Linux apt-get Command: Run APT Package Operations in Scripts

Learn how to run APT Package Operations in Scripts with the Linux apt-get command, including practical examples, key options, and important precautions.

Linux nice Command: Set a New Process's Scheduling Priority

Linux nice Command: Set a New Process's Scheduling Priority

Learn how to set a New Process's Scheduling Priority with the Linux nice command, including practical examples, key options, and important precautions.

Linux top Command: Monitor Processes in Real Time

Linux top Command: Monitor Processes in Real Time

Learn how to monitor Processes in Real Time with the Linux top command, including practical examples, key options, and important precautions.

Linux touch Command: Create Files and Change Timestamps

Linux touch Command: Create Files and Change Timestamps

Learn how to use the Linux touch command to create empty files and change access or modification timestamps, including reference times, date formats, and symlink handling.