Skip to content
shellmap

copy-itemPowerShell's copy cmdlet — the cp equivalent across all 5 shells

Equivalents in every shell

Bashunix
cp source dest

POSIX `cp` copies a single file. `-r` (or `-R`) recursively copies directories; `-a` (GNU) is `-dR --preserve=all` — the canonical "exact archive copy". `-i` prompts on overwrite, `-n` skips existing, `-u` only copies if newer, `-v` prints each copy.

Zshunix
cp source dest

Same `/bin/cp`. macOS BSD `cp` differs from GNU `cp` on long flags — BSD has no `--preserve=all`, use `-p` (mode/owner/timestamps) or `-pP` (also no-symlink-follow). For "exactly Linux semantics" on Mac install coreutils (`brew install coreutils` → `gcp`).

Fishunix
cp source dest

Same external `cp`. Fish has no copy builtin. For atomic-write patterns the idiom is `cp source.tmp dest && rm source.tmp` rather than directly editing `dest`.

PowerShellwindows
Copy-Item -Path source -Destination dest

PowerShell-native cmdlet (aliases `cp`, `copy`, `cpi`). `-Recurse` copies directories; `-Container:$false` copies just the contents (rare). `-Force` overwrites read-only / hidden destinations; `-Filter "*.log"` filters at the provider level (fast); `-Include`/`-Exclude` post-filter (slower). Works across PS providers.

cmd.exewindows
copy source dest

Built-in `copy` does single files; `xcopy` (and the modern `robocopy`) handles directories. `copy /Y` suppresses overwrite prompt; `/B` forces binary mode; `/A` ASCII (treats Ctrl-Z as EOF). `xcopy /E /I /H /Y src dst` is the canonical recursive directory copy with hidden files. `robocopy src dst /MIR` is the modern mirror.

Worked examples

Copy a single file

Bash
cp source.txt dest.txt
Zsh
cp source.txt dest.txt
PowerShell
Copy-Item source.txt dest.txt
cmd.exe
copy source.txt dest.txt

Recursively copy a directory tree

Bash
cp -a src/ dst/
Zsh
cp -a src/ dst/
PowerShell
Copy-Item -Path src -Destination dst -Recurse
cmd.exe
xcopy /E /I /H /Y src dst

Copy with overwrite, preserving timestamps

Bash
cp -fp source.txt dest.txt
PowerShell
Copy-Item source.txt dest.txt -Force

Gotchas

  • `Copy-Item -Recurse` does NOT preserve NTFS ACLs — it copies the file content + standard attributes only. For full ACL-preserving copies use `robocopy /E /COPY:DATSO` (the COPY: flag bits are Data, Attributes, Timestamps, Security, Owner). Unix `cp -p` preserves mode/owner/timestamp but not extended attributes (`xattr`); use `cp -a` (GNU) or `tar -cf - src | (cd dst && tar -xf -)` for that.
  • Trailing `\` on `Copy-Item -Destination` does not change behaviour the way it does on Unix `cp` — `Copy-Item file.txt subdir\` and `Copy-Item file.txt subdir` behave identically (use `subdir` as a directory if it exists, else as the new file name). Always `Test-Path -PathType Container` if you depend on directory semantics.
  • Cross-volume copies via `Copy-Item` use the .NET `File.Copy` API and BUFFER through managed memory; very large files (>2 GB) are slower than `xcopy` / `robocopy` / Unix `cp` which use OS-level fast-path copy. For multi-GB moves, drop to `robocopy` on Windows or `cp --reflink=auto` on btrfs/XFS for instant CoW copies.
  • `Copy-Item -Recurse src dst` when `dst` does NOT exist creates `dst` and puts the CONTENTS of `src` inside it — same as `cp -r src/ dst/` (with the trailing slash on src). When `dst` DOES exist, `Copy-Item` puts `src` INSIDE `dst` as `dst/src/` — same as `cp -r src dst/` (no trailing slash on src). The asymmetry is identical to Unix; both surprise people the first time.
  • cmd `copy` only copies files. `copy mydir target` will ERROR with 'The system cannot find the file specified' rather than silently doing nothing useful — you must use `xcopy` / `robocopy` for directories. The `/B` (binary) and `/A` (ASCII) flags interact with the special CTRL-Z byte; mixed mode (`copy /B file1 + /A file2 dest`) is a frequent source of corruption when concatenating logs.

WSL & PowerShell Core notes

pwsh`Copy-Item` works on Linux/macOS pwsh against the file system provider — identical syntax. `cp`, `copy`, `cpi` aliases are removed on Linux/macOS pwsh so `/bin/cp` resolves first; spell `Copy-Item` in cross-platform scripts. For very large copies on cross-platform pwsh, `& cp -a src dst` (Unix) / `& robocopy src dst /E` (Windows) outperform `Copy-Item -Recurse`.
WSLCross-boundary copies are slow on the Windows side (`Copy-Item \\wsl$\Ubuntu\home\me\src C:\dst -Recurse`) — DrvFs / 9P overhead. From inside WSL, `cp -a src /mnt/c/Users/me/dst` is faster but the destination loses Linux ownership/permissions (NTFS does not have a native uid:gid model unless `metadata` is enabled in `/etc/wsl.conf`).

Common tasks using copy-item

Related commands