Move And Rename A File
Part of the Fundamentals section of Coddy's Terminal journey — lesson 13 of 82.
The mv command stands for move. It is used to move a file to a different location or to rename a file — both actions use the exact same command.
The basic format is:
mv source destinationRenaming a file:
To rename readme.txt to info.txt:
mv readme.txt info.txtThe file stays in the same directory but now has a new name.
Moving a file to another directory:
To move readme.txt into the documents folder:
mv readme.txt documents/The original file is removed from the current directory and placed inside documents.
Moving and renaming at the same time:
You can move a file to a new location and give it a new name in one command:
mv readme.txt documents/info.txtNote: Unlike cp, mv does not keep the original file — it is moved, not copied.
Use -i to get a prompt before overwriting an existing file:
mv -i readme.txt documents/Challenge
BeginnerRename readme.txt to info.txt using the mv command, then use ls to confirm the change.
Hint: The format is
mv old_name new_name. Notice thatreadme.txtwill no longer exist after renaming.
Cheat sheet
The mv command is used to move or rename files.
Basic syntax:
mv source destinationRenaming a file:
mv readme.txt info.txtMoving a file to another directory:
mv readme.txt documents/Moving and renaming simultaneously:
mv readme.txt documents/info.txtNote: mv does not keep the original file — it moves it, not copies it.
Use -i flag to prompt before overwriting existing files:
mv -i readme.txt documents/Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline