•Arnošt Havelka
Moving and Renaming Files
Use mv to move files between directories and rename them.
Start Interactive LessonThe mv command moves and renames files. It's faster than copy-then-delete because it doesn't duplicate data.
Rename a File
Use mv oldname newname to rename a file in the same directory.
Try the command
Rename a file!
Build the command
mvoldnamenewname
mvMove or rename - relocates or renames files and directories.
Terminal
C:\Users\User>mv oldname newname
Change a name:
Command Prompt
draft.txt
C:\Users\User>ls
Move to Another Directory
Use mv file directory/ to move a file to a different folder.
Try the command
Move file to another folder!
Build the command
mvfile.txtdirectory/
directory/Target directory - relocates file to the specified folder.
Terminal
C:\Users\User>mv file.txt directory/
Relocate a file:
Command Prompt
file.txt
Archive/
ls Archive/
C:\Users\User>ls
Move and Rename Together
Combine both operations by specifying the full path with a new name.
Try the command
Move and rename together!
Build the command
mvfile.txtdirectory/newname.txt
directory/newnameFull path with new name - moves and renames in one step.
Terminal
C:\Users\User>mv file.txt directory/newname.txt
Two operations at once:
Command Prompt
draft.txt
C:\Users\User>ls
Knowledge Check
1 / 3What does mv do?
References
These documentation links provide authoritative details for the commands used in this article.