Menu
Coddy logo textTech

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 destination

Renaming a file:

To rename readme.txt to info.txt:

mv readme.txt info.txt

The 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.txt

Note: 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 icon

Challenge

Beginner

Rename 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 that readme.txt will no longer exist after renaming.

Cheat sheet

The mv command is used to move or rename files.

Basic syntax:

mv source destination

Renaming a file:

mv readme.txt info.txt

Moving a file to another directory:

mv readme.txt documents/

Moving and renaming simultaneously:

mv readme.txt documents/info.txt

Note: 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

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals