Skip to content
shellmap

zipPackage and compress files into a ZIP archive across all 5 shells

Equivalents in every shell

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

Native cmdlet since PowerShell 5.0. Capped at 2GB on older versions; use 7-Zip for larger archives.

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

`tar -a` infers the format from the extension. No native `zip.exe`; this is the built-in way on Windows 10 1803+.

Worked examples

Create a zip of a directory recursively

Bash
zip -r project.zip project/
PowerShell
Compress-Archive -Path project -DestinationPath project.zip
cmd.exe
tar -a -cf project.zip project

Extract a zip file

Bash
unzip archive.zip
PowerShell
Expand-Archive archive.zip -DestinationPath .
cmd.exe
tar -xf archive.zip

Update / add files to an existing zip

Bash
zip -u archive.zip newfile.txt
PowerShell
Compress-Archive -Path newfile.txt -Update -DestinationPath archive.zip

Gotchas

  • macOS and many Linux distros do not install `zip`/`unzip` by default; use the system package manager (`brew install zip`, `apt install zip unzip`).
  • macOS Finder’s "Compress" adds a `__MACOSX/` metadata folder and `.DS_Store` files — strip with `zip -d archive.zip "__MACOSX*" "*.DS_Store"`.
  • ZIP filenames are encoded as CP437 or UTF-8 depending on tool. Non-ASCII names created on Windows may extract as mojibake on Unix and vice versa.
  • `Compress-Archive` is slow on large inputs (re-reads everything on `-Update`). Use 7-Zip CLI or `tar -a -cf` for serious workloads.

WSL & PowerShell Core notes

pwsh`Compress-Archive` is the cross-platform pwsh cmdlet (pwsh 5.1+ on Windows, pwsh 7+ on Linux/macOS) but has hard limits: ~2GB total archive size on pwsh 5.1, slow on large inputs (re-reads everything on `-Update`), no fine-grained compression-level control, and no per-file mode-bit preservation. For serious archive work on any platform, shell out to `tar -a -cf out.zip ...` (uses libarchive, handles long paths, faster) or install 7-Zip CLI (`7z a out.zip ...`).
WSLInside WSL, GNU `zip` / `unzip` are available via the distro package manager (`apt install zip unzip`, `dnf install zip unzip`) — they are NOT pre-installed on most distros despite being assumed by many tutorials. Zipping `/mnt/c/...` paths preserves DrvFs-translated POSIX modes inside the archive, but if you unzip the same archive with Windows-native Explorer or `Expand-Archive`, the mode bits are silently dropped (Windows ZIP only tracks read-only). For Windows ↔ Linux round-trip safety, use `zip -X` to strip extra-attributes, or accept that POSIX modes are a Linux-only concept.

Common tasks using zip

Related commands