ShareYourGroupShareYourGroupCommands

Windows commands

copy, move and ren: copy, move and rename files

These commands do from the keyboard what dragging does in File Explorer. They are quick for single files and far quicker than the mouse for groups of files chosen by a pattern, such as "every .txt file".

copy

copy takes a source and a destination.

Windows Command Prompt
C:\Users\asha\demo>copy notes.txt notes-backup.txt
        1 file(s) copied.
C:\Users\asha\demo>copy notes.txt old
        1 file(s) copied.
C:\Users\asha\demo>dir /b old
draft.txt
notes.txt

The first command made a copy under a new name in the same folder. The second put a copy into the folder old, keeping the name.

Wildcards copy several files at once.

Windows Command Prompt
C:\Users\asha\demo>mkdir backup
C:\Users\asha\demo>copy *.txt backup
log.txt
notes-backup.txt
notes.txt
report.txt
        4 file(s) copied.

Danger. If a file of the same name is already at the destination, copy asks before replacing it when you type the command yourself, but not when the command runs inside a batch file, and not if you add /y. Replacing a file destroys the old one. There is no Recycle Bin for this.

What copy cannot do

copy handles files, not folders. Given a folder name as the source, it copies the files directly inside and ignores subfolders. For whole folders, use xcopy or robocopy.

xcopy: folders and all

Windows Command Prompt
C:\Users\asha\demo>xcopy photos photos-copy /e /i
photos\beach.jpg
photos\hills.jpg
2 File(s) copied
C:\Users\asha\demo>dir /s /b photos-copy
C:\Users\asha\demo\photos-copy\beach.jpg
C:\Users\asha\demo\photos-copy\hills.jpg

Other useful switches: /d copies only files newer than those already at the destination, /h includes hidden files, and /y stops it asking before overwriting.

robocopy: for serious copying

robocopy, short for robust copy, is the tool for backups and large folders. It can resume after an interruption, copy only what has changed, and write a log.

Windows Command Prompt not run here
robocopy C:\Users\asha\Documents D:\Backup\Documents /e

The order is source folder, destination folder, then options. /e includes subfolders. Run again later, it copies only new and changed files.

Danger. robocopy /mir makes the destination an exact mirror of the source. That means it also deletes from the destination anything that is not in the source. Pointed at the wrong folder, it can empty it. Add /l first: that lists what would happen without doing anything.

move

move takes a file from one place and puts it in another. The original is gone from where it was.

Windows Command Prompt
C:\Users\asha\demo>move report.txt old
        1 file(s) moved.
C:\Users\asha\demo>dir /b old
draft.txt
notes.txt
report.txt

Giving a new name at the destination moves and renames in one step. move also renames folders.

Windows Command Prompt
C:\Users\asha\demo>move old archive
        1 dir(s) moved.
C:\Users\asha\demo>dir /ad /b
archive
backup
photos
photos-copy

Like copy, move asks before overwriting when typed by hand, and /y suppresses the question.

ren: rename

Windows Command Prompt
C:\Users\asha\demo>ren notes.txt todo.txt
C:\Users\asha\demo>dir /b *.txt
log.txt
notes-backup.txt
todo.txt

ren changes the name only. It cannot move a file to another folder, so the new name must not include a path.

Wildcards rename in bulk. This changes the ending of every .txt file to .bak:

Windows Command Prompt
C:\Users\asha\demo>ren *.txt *.bak
C:\Users\asha\demo>dir /b
archive
backup
log.bak
marks.csv
notes-backup.bak
photos
photos-copy
todo.bak

Changing a file's ending does not change what is inside it. A text file renamed to .jpg is still text, and will not open as a picture.

Names with spaces

Any name containing a space needs double quotation marks, or the command treats it as two names: copy "annual report.txt" backup.

Checking before a bulk change

Before copying, moving or renaming with a wildcard, run dir with the same pattern. It shows exactly which files the pattern matches.

Windows Command Prompt
C:\Users\asha\demo>dir /b *.bak
log.bak
notes-backup.bak
todo.bak

Summary

JobCommand
copy a filecopy source destination
copy a folder with its contentsxcopy source destination /e /i
back up or synchronise a folderrobocopy source destination /e
move a file or foldermove source destination
renameren oldname newname

On Linux and the Mac, see cp and mv.

Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.

This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.