Definition:
When you use the mv command in your terminal and press enter, it moves a file or directory from its original location to the specified destination.
It works in two ways: move the file or directory to another location, or rename it with a new name.
You can move a file within the current directory using a relative path, or use an absolute path to move it anywhere on the system.
Syntax:
mv [source] [destination]
Example 1: Rename a file
Command:
mv file1.txt file2.txt
Explanation:
file1.txtis renamed asfile2.txt.- In the source, the file name is
file1.txt. - The
mvcommand changes the file name tofile2.txtas soon as it runs. - Only the name is updated; the content remains the same.
Example 2: Move with relative path
Command:
mv file1.txt ./Documents/
Explanation:
file1.txtis moved to theDocumentsfolder.- The source file
file1.txtis in the current directory.
