Skip to content
shellmap

cpCopy files and directories across all 5 shells

Equivalents in every shell

Bashunix
cp source dest
Zshunix
cp source dest
Fishunix
cp source dest
PowerShellwindows
Copy-Item source dest

Aliased as `cp`, `copy`, `cpi`.

cmd.exewindows
copy source dest

Use `xcopy` or `robocopy` for directories.

Worked examples

Copy a directory recursively

Bash
cp -r src dst
PowerShell
Copy-Item src dst -Recurse
cmd.exe
xcopy src dst /e /i

Copy preserving timestamps and attributes

Bash
cp -p file dest
PowerShell
Copy-Item file dest
cmd.exe
xcopy file dest /k

Mirror a directory (delete extras at dest)

Bash
rsync -a --delete src/ dst/
PowerShell
robocopy src dst /MIR
cmd.exe
robocopy src dst /MIR

Gotchas

  • PowerShell `cp` is `Copy-Item`, not Unix `cp` — flag syntax differs (`-Recurse`, not `-r`).
  • `xcopy` is deprecated in favor of `robocopy` on modern Windows; robocopy has saner defaults and exit codes.
  • Trailing slash on source path matters in `rsync` and Unix `cp -r`; on Windows tools it does not.

WSL & PowerShell Core notes

pwshOn Linux/macOS PowerShell Core, the `cp` alias for `Copy-Item` is removed and `/bin/cp` wins. On Windows pwsh the alias is intact. Use `Copy-Item` explicitly in scripts that target both platforms.
WSLCopying across the WSL ↔ Windows boundary (`/mnt/c/...`) goes through the DrvFs adapter and is roughly an order of magnitude slower than copying within the Linux filesystem (`~`). Keep build artifacts under `~` and only push final outputs to `/mnt/c` if you must.

Common tasks using cp

Related commands