cheat sheet
move
Move files to a new location or rename them within the Windows command prompt. Covers single files, wildcards, directory renames, overwrite control, and cross-drive behaviour.
move — Move and Rename Files
What it is
move is a built-in cmd.exe command that either moves files to a different directory or renames a file or directory. Unlike copy, the source is removed after the transfer completes. Moving within the same drive is near-instantaneous (a directory-entry update); moving across drives performs a copy then delete, which takes proportional time. For robust cross-drive or network moves with retry logic, use robocopy /MOV or robocopy /MOVE instead.
Availability
move is built into cmd.exe on every Windows version. PowerShell equivalent: Move-Item (aliased move, mv, mi).
move /?
Output:
Moves files and renames files and directories.
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
Syntax
The source can be a single file or wildcard pattern; the destination is a file path or directory. Renaming a directory uses the same command with two directory paths.
move [/Y | /-Y] source destination
Output: (shows 1 file(s) moved or error)
Essential options
| Switch | Meaning |
|---|---|
/Y | Overwrite existing destination without prompting |
/-Y | Prompt before overwriting an existing destination file |
Moving a single file
If the destination is an existing directory, move places the file inside it keeping the original name. If the destination is a new name in the current or another directory, it renames/moves simultaneously.
rem Move into a directory (keeps filename)
move report.docx C:\Archive\
Output:
1 file(s) moved.
rem Move and rename in one step
move C:\Temp\draft.txt C:\Documents\final_report.txt
Output:
1 file(s) moved.
rem Move to another drive (copy + delete internally)
move C:\Exports\data.csv D:\Processed\data.csv
Output:
1 file(s) moved.
Renaming a file
When source and destination are in the same directory, move acts as a rename.
move old_name.txt new_name.txt
Output:
1 file(s) moved.
rem Rename with a full path
move C:\Projects\myapp\main.py C:\Projects\myapp\app.py
Output:
1 file(s) moved.
Wildcard moves
Wildcards move all matching files into a destination directory. The destination must be an existing directory when a wildcard is used; specifying a filename with wildcards only captures the last match.
rem Move all .log files to an archive folder
move *.log C:\Archive\Logs\
Output:
4 file(s) moved.
rem Move all files starting with "report"
move report*.docx C:\Reports\
Output:
3 file(s) moved.
Renaming a directory
move is the only built-in cmd.exe way to rename a directory without moving its contents to a different drive.
rem Rename a directory (both paths on same drive)
move C:\Projects\old_name C:\Projects\new_name
Output:
1 dir(s) moved.
rem Rename relative to current location
move drafts archive
Output:
1 dir(s) moved.
Overwrite control
By default in interactive sessions, move prompts before overwriting an existing destination file. Use /Y in scripts to suppress the prompt.
rem Silent overwrite — use in scripts
move /Y source.txt C:\Dest\source.txt
Output:
1 file(s) moved.
rem Force prompt even if environment suppresses it
move /-Y source.txt C:\Dest\source.txt
Output:
Overwrite C:\Dest\source.txt? (Yes/No/All):
Paths with spaces
Enclose paths in double quotes whenever a directory or filename contains spaces.
move "C:\My Documents\Q1 draft.docx" "C:\Reports\Q1 final.docx"
Output:
1 file(s) moved.
Common pitfalls
- Cross-drive moves are slow —
movecopies then deletes across drives; progress is not shown. Userobocopy /MOVfor large cross-drive moves with progress feedback. - Wildcards require an existing directory destination —
move *.txt output.txtmoves only the last matched file intooutput.txt(or errors); always supply a directory for multi-file moves. - Cannot move an open file — a file locked by another process returns "Access is denied". Close the owning application first.
movecannot move directories across drives —move C:\Projects\myapp D:\Projects\myapperrors out. Usexcopy /Ethenrmdir /S /Qto achieve this.- Overwrite prompt blocked in scripts — without
/Y, an unattended script hangs waiting for input when a destination file exists.
Real-world recipes
Move completed exports to a dated archive folder
set ARCH=C:\Archive\%DATE:~-4,4%-%DATE:~-10,2%
if not exist "%ARCH%" mkdir "%ARCH%"
move /Y C:\Exports\*.csv "%ARCH%\"
Output:
6 file(s) moved.
Rename all files matching a pattern in a for loop
for %f in (draft_*.txt) do move "%f" "%~nf_final.txt"
Output:
1 file(s) moved.
1 file(s) moved.
Move and rename a directory as part of a release pipeline
move C:\Build\staging C:\Build\release_v2
echo Release directory prepared.
Output:
1 dir(s) moved.
Release directory prepared.
Move files older than 30 days to archive using forfiles
if not exist C:\Archive mkdir C:\Archive
forfiles /P C:\Logs /M *.log /D -30 /C "cmd /c move /Y @path C:\Archive\"
Output:
1 file(s) moved.
1 file(s) moved.
Same-drive vs cross-drive semantics
A move within the same volume is a directory-entry rename: the data does not change blocks, and the operation is essentially instantaneous regardless of file size. A move across volumes is implemented internally as copy then del — the data is physically transferred byte-by-byte, and a 4 GB cross-drive move takes the same time as a copy followed by a delete. Knowing the difference is essential when scripting: a same-drive move is atomic on NTFS; a cross-drive move is not, and an interrupted transfer can leave a partial file at the destination plus the original at the source.
rem Same drive — instant (directory entry update)
move C:\Projects\large.dat C:\Archive\large.dat
Output:
1 file(s) moved.
rem Cross drive — copy + delete; size-proportional time
move C:\Projects\large.dat D:\Archive\large.dat
Output:
1 file(s) moved.
rem For large cross-drive transfers, robocopy /MOV is more robust
robocopy C:\Projects D:\Archive large.dat /MOV /R:3 /W:5
Output:
Files : 1 1 0 0 0 0
Bytes : 4.2 g 4.2 g 0 0 0 0
Atomicity guarantees
A same-volume rename via move issues SetFileInformationByHandle(FileRenameInfo), which the NTFS driver completes atomically — observers either see the old name or the new, never both, never neither. A cross-volume move has no such guarantee: if the machine loses power mid-transfer, the source may still exist and the destination may be partial. For deployment scripts that require atomic publishing, copy to a temporary name on the destination volume, then move (rename) into place.
rem Atomic publish pattern
copy /Y C:\Build\app.exe C:\Deploy\app.exe.new
move /Y C:\Deploy\app.exe.new C:\Deploy\app.exe
Output:
1 file(s) copied.
1 file(s) moved.
Moving directories
move can rename a directory or relocate it within the same drive in O(1) time. It cannot move a directory across drives — that operation requires xcopy /E plus rmdir /S /Q, or robocopy /MOVE which handles both halves with retry and logging.
rem Rename a directory on the same drive
move C:\Projects\old_name C:\Projects\new_name
Output:
1 dir(s) moved.
rem Cross-drive directory move fails
move C:\Projects\myapp D:\Projects\myapp
Output:
The system cannot move the file to a different disk drive.
rem Use robocopy /MOVE for cross-drive directory relocation
robocopy C:\Projects\myapp D:\Projects\myapp /E /MOVE /R:3 /W:5
Output:
Dirs : 5 5 0 0 0 0
Files : 42 42 0 0 0 0
Open-file behaviour and locking
move fails on a file that is open in another process — even if that process only has read access. The error is "Access is denied" or "The process cannot access the file because it is being used by another process". Use handle.exe (Sysinternals) to identify the locker, or Restart-Service / close the application first. Files mapped into a running process (DLLs, executables) cannot be moved at all on the same volume — they can be renamed on disk but the running image keeps the old path.
move running_app.exe staged.exe
Output:
1 file(s) moved.
rem Locked by another process — fails
move open_log.txt archived_log.txt
Output:
The process cannot access the file because it is being used by another process.
MoveFileEx and reboot-time moves
The Win32 API offers MoveFileEx with the MOVEFILE_DELAY_UNTIL_REBOOT flag, which queues a move to occur during the next system startup before file handles are opened. This is how installers schedule replacement of in-use files. The cmd.exe move builtin does not expose this; use PowerShell or a small script.
# Schedule a move at next reboot — useful for replacing locked DLLs
$src = "C:\Temp\new_driver.sys"
$dst = "C:\Windows\System32\drivers\driver.sys"
Add-Type @"
using System.Runtime.InteropServices;
public class FS {
[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
public static extern bool MoveFileEx(string src, string dst, uint flags);
}
"@
[FS]::MoveFileEx($src, $dst, 5) # MOVEFILE_REPLACE_EXISTING | MOVEFILE_DELAY_UNTIL_REBOOT
Output:
True
PowerShell equivalents
Move-Item (aliases move, mv, mi) is the PowerShell native. It handles single files, wildcards, directories, cross-drive moves transparently, and exposes -WhatIf, -Confirm, -Force, -Filter, and pipeline input. PowerShell's move is not the cmd builtin — it is Move-Item with PowerShell semantics.
# Single file move
Move-Item report.docx C:\Archive\
Output: (none — silent success)
# Move and rename
Move-Item C:\Temp\draft.txt C:\Documents\final.txt
Output: (none — silent success)
# Wildcard
Move-Item C:\Exports\*.csv C:\Archive\
Output: (none — silent success)
# Cross-drive (transparent — Move-Item handles copy+delete)
Move-Item C:\Big\file.iso D:\Storage\file.iso
Output: (none — silent success)
# Move with overwrite via -Force
Move-Item source.txt dest.txt -Force
Output: (none — silent success)
# Dry run
Move-Item C:\Temp\* C:\Archive\ -WhatIf
Output:
What if: Performing the operation "Move File" on target "Item: C:\Temp\a.txt Destination: C:\Archive\a.txt".
# Pipeline: move all .log files older than 30 days
Get-ChildItem C:\Logs -Filter *.log |
Where-Object LastWriteTime -lt (Get-Date).AddDays(-30) |
Move-Item -Destination C:\Archive\
Output: (none — silent success)
# Rename pattern with -NewName
Get-ChildItem draft_*.txt | Rename-Item -NewName { $_.Name -replace '^draft_','final_' }
Output: (none — silent success)
CMD vs PowerShell vs bash comparison
| Goal | CMD | PowerShell | bash (Linux/macOS) |
|---|---|---|---|
| Move file | move a b | Move-Item a b | mv a b |
| Move with overwrite | move /Y a b | Move-Item a b -Force | mv -f a b |
| Rename file | move old new (same dir) | Rename-Item old new or Move-Item old new | mv old new |
| Rename directory | move olddir newdir (same drive) | Rename-Item olddir newdir | mv olddir newdir |
| Cross-drive file | move a D:\b (copy+delete) | Move-Item a D:\b (transparent) | mv a /mnt/d/b (copy+delete on different fs) |
| Cross-drive directory | (fails — use robocopy /MOVE) | Move-Item dir D:\ (works) | mv dir /mnt/d/ |
| Move many by pattern | move *.log C:\Archive\ | Move-Item *.log C:\Archive\ | mv *.log /archive/ |
| Dry run | (none built in) | Move-Item -WhatIf | (none; use echo mv ...) |
| Move locked file | (fails) | (fails — use Move-Item -Force or MoveFileEx reboot) | mv (Linux usually allows; ext4 unlinks safely) |
| Move with retry | (none — use robocopy /MOV /R:n /W:n) | (manual retry loop) | (manual retry) |
| Move + log | (redirect output) | Move-Item ... -Verbose | mv -v |
Common pitfalls (continued)
- Cross-drive moves are not atomic — power loss mid-transfer leaves a partial file. For critical pipelines, copy then rename within the same volume, or use a journaled transaction layer.
- Same name on same volume is a no-op or error —
move foo.txt foo.txtmay succeed silently or fail depending oncmd.exebuild. Avoid relying on it. movedoes not preserve archive bit — the destination file gets a fresh archive bit. If backup software relies on that bit, set it explicitly afterwards withattrib +A.- Spaces in either side need quoting —
move "C:\My Docs\a.txt" "C:\My Backup\a.txt"is mandatory when either path contains spaces. - Wildcards collapse to last match with file destination —
move *.txt out.txtoverwritesout.txtonce per matched file, leaving only the last. Always supply a directory destination. - Locked files block the entire move — a wildcard move that hits a single locked file aborts after the lock. Pre-filter or use
robocopy /MOVwhich logs and skips locked entries. - OneDrive online-only files — moving a cloud placeholder hydrates the file first. Bulk moves may unexpectedly consume bandwidth.
- EFS-encrypted file to non-EFS target fails — Microsoft Learn explicitly warns that moving an Encrypting File System–encrypted file to a volume that does not support EFS (FAT32, exFAT, ReFS, network shares without EFS) returns an error. Decrypt first with
cipher /Dor pick an NTFS destination on the same trust boundary. COPYCMDenvironment variable can silently preset/Y— if the shell hasCOPYCMD=/Yexported (some build environments do), interactive prompts disappear without the operator realising. Use/-Yto force the prompt back when you actually want confirmation.
Real-world recipes (continued)
Atomic deployment via stage-then-rename
rem Stage to .new on the destination volume, then atomic rename
copy /Y C:\Build\release.exe C:\Deploy\release.exe.new
move /Y C:\Deploy\release.exe.new C:\Deploy\release.exe
echo Deployed.
Output:
1 file(s) copied.
1 file(s) moved.
Deployed.
Bulk rename with a for loop
for %f in (*.jpg) do move "%f" "vacation_%~nf%~xf"
Output:
1 file(s) moved.
1 file(s) moved.
1 file(s) moved.
Move directory across volumes safely with robocopy
robocopy C:\Projects\old D:\Projects\old /E /MOVE /R:3 /W:5 /MT:8 /NP /LOG:C:\Logs\move.log
if %ERRORLEVEL% GEQ 8 echo Move failed; check log
Output: (log written; success or failure messaged)
Daily archive rotation
@echo off
setlocal EnableExtensions
set ARCHROOT=C:\Archive
set STAMP=%DATE:~-4,4%%DATE:~-10,2%%DATE:~-7,2%
set ARCH=%ARCHROOT%\%STAMP%
if not exist "%ARCH%" mkdir "%ARCH%"
move /Y C:\Exports\*.csv "%ARCH%\" >NUL
echo Archived to %ARCH%
endlocal
Output:
Archived to C:\Archive\20260525
PowerShell: move with collision-safe renaming
function Move-WithVersion {
param($Source, $Dest)
$i = 0
$target = Join-Path $Dest (Split-Path $Source -Leaf)
while (Test-Path $target) {
$i++
$base = [IO.Path]::GetFileNameWithoutExtension($Source)
$ext = [IO.Path]::GetExtension($Source)
$target = Join-Path $Dest "${base}_$i$ext"
}
Move-Item -LiteralPath $Source -Destination $target
}
Move-WithVersion C:\Inbox\report.docx C:\Archive
Output: (none — silent success; renames to report_1.docx if collision)
Move-and-delete in one expression with robocopy /MOVE
robocopy C:\Source\complete D:\Done /E /MOVE /R:3 /W:5 /MT:8 /NP
Output:
Files : 20 20 0 0 0 0
See also
copy— non-destructive equivalent; copy + delete is sometimes safer than move.xcopy— recursive directory copy; pair withrmdir /S /Qto emulate cross-drive directory move.robocopy /MOVand/MOVE— production-grade move with retry, logging, and cross-drive directory support.del— explicit delete after a copy, when you want to inspect the destination before removing.ren(orrename) — file rename only; cannot move between directories.- PowerShell
Move-Item,Rename-Item— typed alternatives with pipeline support. - Linux
mv,rsync --remove-source-files— Unix equivalents.
Sources
- move — Microsoft Learn