Archives and compression

Command zip

Create zip-archive

Linux · Bash examples · commands run on the selected server

When to use zip

Use zip to create or update a ZIP archive for file exchange. Verify exclusions and archive contents because including repository metadata, configuration secrets or stale entries can expose more data than intended.

Syntax

zip [PARAMETERS] ARCHIVE.zip FILE…

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-r
Recursively include a directory.
-u
Update changed files and add new ones.
-x TEMPLATE
Exclude matching names.

Usage examples

Create a ZIP archive of a directory

zip -r ./project.zip ./project

The project directory is added recursively to the archive.

Exclude Git metadata

zip -r ./project.zip ./project -x '*/.git/*'

Repository metadata paths matching the exclusion are omitted from this operation.

Update a specific file

zip -u ./project.zip ./project/README.md

The named entry is added or updated when appropriate; unrelated archive entries are not automatically removed.

Notes and limitations

  • Adding to an existing archive updates it, but does not necessarily remove old entries.
  • Do not specify a password as a command line option; Consider compatibility and ZIP encryption limitations.

Common questions and troubleshooting

Does updating an archive remove deleted source files?

Not by default. Existing entries can remain even when absent from the current source. Build a fresh archive when exact contents matter.

Is a ZIP archive an encrypted backup by default?

No. Ordinary archive creation provides no secrecy. Use a suitable secure storage and encryption workflow for confidential backups.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man zip.