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 destinationRenaming a directory:
To rename the documents folder to files:
mv documents filesThe 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/filesNote: 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
BeginnerRename 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 destinationRenaming a directory:
mv documents filesMoving a directory into another directory:
mv documents projects/Moving and renaming simultaneously:
mv documents projects/filesNote: Unlike cp -r, mv does not keep the original directory — it moves it entirely.
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