Skip to main content

Command referencexcopy

xcopy command (Windows / CMD)

WindowsCMDfilebeginner

What it does

Copy files and directory trees with filtering and overwrite controls. Searches for the xcopy command cmd usually need CMD syntax, practical switches, and notes on how it compares with PowerShell or Linux alternatives. This page covers syntax, common options, and copyable examples for Command Prompt.

Copy files and directory trees with filtering and overwrite controls.

Syntax

xcopy source [destination] [/S] [/E] [/I] [/Y] [/D[:date]]

Common options

Flag / optionMeaning
/SCopy nonempty subdirectories.
/EInclude empty subdirectories.
/IAssume the destination is a directory.
/YSuppress overwrite prompts.
/DCopy newer files only.

Practical examples

Copy tree

xcopy C:\Docs D:\DocsBackup /E /I

Copies the complete Docs tree.

Newer files

xcopy C:\Data D:\Data /D /S /Y

Updates destination files without prompts.

Confirm replacement

xcopy report.txt D:\Archive\ /-Y

Prompts before overwrite.

Linux ↔ Windows equivalent

Closest match: cp (Linux / bash / sh / zsh). Copy files or directory trees to another location.

Common mistakes

  • Using legacy xcopy for resilient synchronization where robocopy is better.
  • Forgetting `/E` and silently omitting empty directories.

FAQ

What does xcopy do in Command Prompt?

Copy files and directory trees with filtering and overwrite controls.

How do I run xcopy in CMD?

Open Command Prompt and follow `xcopy source [destination] [/S] [/E] [/I] [/Y] [/D[:date]]`; quote paths containing spaces.

What is a practical xcopy example in CMD?

Try `xcopy C:\Docs D:\DocsBackup /E /I` — Copies the complete Docs tree.

Can xcopy be used in a batch file?

Yes. Check its exit code and escape CMD metacharacters when input is variable.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.