copy-item — PowerShell's copy cmdlet — the cp equivalent across all 5 shells
Equivalents in every shell
cp source destPOSIX `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.
cp source destSame `/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`).
cp source destSame 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`.
Copy-Item -Path source -Destination destPowerShell-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.
copy source destBuilt-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
cp source.txt dest.txtcp source.txt dest.txtCopy-Item source.txt dest.txtcopy source.txt dest.txtRecursively copy a directory tree
cp -a src/ dst/cp -a src/ dst/Copy-Item -Path src -Destination dst -Recursexcopy /E /I /H /Y src dstCopy with overwrite, preserving timestamps
cp -fp source.txt dest.txtCopy-Item source.txt dest.txt -ForceGotchas
- `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.