Skip to content
shellmap

Compress files into a zip archive

Bundle a folder or set of files into a single `.zip` archive.

How to compress files into a zip archive in each shell

Bashunix
zip -r archive.zip folder/

`-r` recurses into the folder. Add `-x "*.git/*"` to exclude patterns. On many distros `zip` is not preinstalled — apt/yum to add it.

Zshunix
zip -r archive.zip folder/
Fishunix
zip -r archive.zip folder/
PowerShellwindows
Compress-Archive -Path folder -DestinationPath archive.zip

Cmdlet has a 2 GB total-uncompressed-size limit and is slow on large trees. For big jobs use `[System.IO.Compression.ZipFile]::CreateFromDirectory("folder","archive.zip")`.

cmd.exewindows
tar -a -cf archive.zip folder

Windows 10 1803+ ships `bsdtar`; `-a` makes it pick the zip format from the `.zip` extension. Older Windows: `powershell -Command "Compress-Archive ..."`.

Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.

Gotchas & notes

  • PowerShell `Compress-Archive` refuses an existing destination unless you pass `-Force`. `zip` happily appends to / updates an existing archive instead.
  • `zip -r archive.zip folder/` stores the folder name in the archive. `zip -r archive.zip folder/*` stores files at archive root — the difference matters when unpacking.
  • Compression ratio: `zip` defaults to DEFLATE level 6; `Compress-Archive` defaults to `Optimal` (≈ level 9 in .NET). Use `-CompressionLevel Fastest` if speed beats ratio.
  • For very large datasets prefer `tar -czf archive.tar.gz folder` — single-pass, streams, better compression, and universal on Unix. Zip exists mainly for Windows interop.

Related commands

Related tasks