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 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 tail Command: View the End of a File and Follow Logs

Linux tail Command: View the End of a File and Follow Logs

Learn how to use the Linux tail command to view the last lines of a file and follow log updates in real time, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / Install and Update Packages with APT and DNF

Linux Tutorial / Install and Update Packages with APT and DNF

Compare APT on Debian or Ubuntu with DNF on Rocky Linux for searching, installing, updating, and removing packages, including repository and transaction checks.

Linux watch Command: Run a Command Repeatedly

Linux watch Command: Run a Command Repeatedly

Learn how to use the Linux watch command to rerun a command at regular intervals and highlight changing output, with essential options, practical examples, output interpretation, and common troubleshooting tips.

How to Check the Linux Distribution, Version, Kernel, and Architecture

How to Check the Linux Distribution, Version, Kernel, and Architecture

Learn how to identify a Linux distribution and version with /etc/os-release, then check the running kernel and CPU architecture with hostnamectl and uname. The guide also covers scripts, legacy systems, containers, WSL, and chroot environments.

Linux split Command: Divide Large Files into Smaller Parts

Linux split Command: Divide Large Files into Smaller Parts

Learn how to divide Large Files into Smaller Parts with the Linux split command, including practical examples, key options, and important precautions.

Linux gunzip Command: Decompress gzip Files

Linux gunzip Command: Decompress gzip Files

Learn how to decompress gzip Files with the Linux gunzip 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 mv Command: Move and Rename Files and Directories

Linux mv Command: Move and Rename Files and Directories

Learn how to move and rename files or directories with Linux mv, avoid unwanted overwrites, clarify destination paths, and handle cross-filesystem moves.

Linux Tutorial / Hard Links vs. Symbolic Links in Linux: Differences and Examples

Linux Tutorial / Hard Links vs. Symbolic Links in Linux: Differences and Examples

Compare hard and symbolic links through inode and path behavior, then create both kinds of link and observe what happens when the original name changes.