Definition:
When you type the mv
command in your terminal, it moves a file or directory from one location to another.
It can also be used to rename files or folders.
You can move a file within the current directory using a relative path,
or move it anywhere in the system using an absolute path.
Syntax:
mv [source] [destination]
Example 1: Rename a file
Command:
$ mv file1.txt file2.txt
Explanation:
- The source file name is
file1.txt
. - The command renames it to
file2.txt
. - Only the name changes, the content remains the same.
Example 2: Move file using relative path
Command:
$ mv file1.txt ./Documents/
Explanation:
file1.txt
is present in the current directory.- The command moves it into the
Documents
folder (relative path).
Example 3: Move file using absolute path
Command:
$ mv file1.txt /home/user/Documents/
Explanation:
- The source file
file1.txt
is in the current directory. - The command moves it to
/home/user/Documents/
(absolute path).