Menu
Coddy logo textTech

Move And Rename A Directory

Part of the Fundamentals section of Coddy's Terminal journey — lesson 18 of 82.

Just like with files, the mv command is used to move or rename a directory. The great thing about mv is that it works the same way for both files and folders — no extra flags needed.

The basic format is:

mv source destination

Renaming a directory:

To rename the documents folder to files:

mv documents files

The folder stays in the same location but now has a new name.

Moving a directory into another directory:

To move the documents folder into a folder called projects:

mv documents projects/

The documents folder is now located at projects/documents.

Moving and renaming at the same time:

You can move a directory to a new location and give it a new name in one command:

mv documents projects/files

Note: Unlike cp -r, mv does not keep the original directory — it is moved entirely. Always double-check your source and destination before running mv.

challenge icon

Challenge

Beginner

Rename the documents directory to files using the mv command, then use ls to confirm the change.

Hint: The format is mv old_name new_name. No extra flags are needed to rename a directory.

Cheat sheet

The mv command is used to move or rename directories (works the same for files and folders):

mv source destination

Renaming a directory:

mv documents files

Moving a directory into another directory:

mv documents projects/

Moving and renaming simultaneously:

mv documents projects/files

Note: Unlike cp -r, mv does not keep the original directory — it moves it entirely.

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