Home·Terminal commands

zip

Archives

Usage

zip -r <archive.zip> <path>

Unlike tar it carries its own compression, and it is the format a Windows machine opens with no extra software; a directory needs `-r` or you archive the folder entry and nothing inside, and the password from `-e` is legacy ZipCrypto and weak.

Common flags

FlagMeaning
-rRecurse into directories. Without it you archive the directory entry and nothing inside.
-x '*/node_modules/*'Exclude a pattern. Quote it so the shell leaves it alone.
-ePrompt for a password. This is legacy ZipCrypto, which is weak.
-1 / -9Fastest / smallest.
-jStore bare file names and drop the directory structure.
-uAdd only files that are new or changed.
-s 100mSplit the archive into 100 MB volumes.

Examples

zip -r site.zip site -x '*/node_modules/*'

The archive a Windows colleague can open, without the dependency tree.

zip -j photos.zip ~/Pictures/*.jpg

One flat archive of files from several places.

Bundling and compressing are separate jobs: tar bundles, gzip shrinks, and .tar.gz is both.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does zip do?

Unlike tar it carries its own compression, and it is the format a Windows machine opens with no extra software; a directory needs `-r` or you archive the folder entry and nothing inside, and the password from `-e` is legacy ZipCrypto and weak.

Q. How do I type it?

zip -r <archive.zip> <path> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man zip. This command sits under Archives.

Related commands

man page: man zip