The mv
command is used in Linux to move files and directories from one location to another, or to rename files and directories. Here is a tutorial on how to use the mv
command:
- Open a terminal window: To access the Linux command line, you can use the terminal application, which is usually found in the “Utilities” or “System Tools” section of the application menu.
- Change to the directory that contains the files you want to move: To change to a different directory, use the
cd
command followed by the path to the directory you want to change to. For example, to change to the/home
directory, you would run the following command:
cd /home
- Move a file: To move a file from one location to another, use the following syntax:
mv source destination
where source
is the path to the file you want to move and destination
is the path to the location where you want to move the file. For example, to move a file named file.txt
from the /home
directory to the /tmp
directory, you would run the following command:
mv /home/file.txt /tmp
- Rename a file: To rename a file, you can use the
mv
command to move the file to the same directory but with a different name. For example, to rename a file namedfile.txt
tonew_file.txt
in the/home
directory, you would run the following command:
mv /home/file.txt /home/new_file.txt
- Move a directory: To move a directory, use the same syntax as for moving a file. For example, to move a directory named
dir
from the/home
directory to the/tmp
directory, you would run the following command:
mv /home/dir /tmp
- Overwrite existing files: By default, the
mv
command will overwrite existing files if the destination is a file. To avoid overwriting existing files, you can use the-n
option:
mv -n source destination
These are just a few examples of how to use the mv
command. The mv
command is a simple but powerful tool for managing files and directories in Linux. To learn more about the mv
command and its options, you can consult the mv
manual page by running the following command:
man mv