Command referencexcopy
xcopy command (Windows / CMD)
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 / option | Meaning |
|---|---|
| /S | Copy nonempty subdirectories. |
| /E | Include empty subdirectories. |
| /I | Assume the destination is a directory. |
| /Y | Suppress overwrite prompts. |
| /D | Copy 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.
Related commands
- robocopyReliably copy and synchronize large directory trees.
- copyCopy one or more files and optionally combine text or binary files.
- cpCopy files or directory trees to another location.
- lsList directory entries and inspect file metadata.
- cdChange the shell's current working directory.
- dirList files and subdirectories with names, dates, sizes, and attributes.
- findWalk directory trees and select entries using tests and actions.
- Get-ChildItemEnumerate items and child items in filesystem, registry, and other providers.
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.