CMD Master
Back to Blog
•Arnošt Havelka

Moving and Renaming Files

Use mv to move files between directories and rename them.

Start Interactive Lesson
Moving and Renaming Files

The 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
mv[source][destination]
mv
Terminal
~$mv old.txt new.txt

Change a name:

Terminal
~$mv draft.txt final.txt 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
mv[source][destination]
mv
directory/Target directory - relocates file to the specified folder.
Terminal
~$mv file.txt ~/Documents/

Relocate a file:

Terminal
~$mv file.txt Archive/ 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
mv[source][destination]
mvold.txt~/Archive/new.txt
directory/newnameFull path with new name - moves and renames in one step.
Terminal
~$mv old.txt ~/Archive/new.txt

Two operations at once:

Terminal
~$mv draft.txt Archive/final.txt ls

Knowledge Check

1 / 3

What does mv do?

References

These documentation links provide authoritative details for the commands used in this article.

Up Next

Removing Files and Directories

Learn rm and rmdir to delete files and directories safely.