Skip to content

mv – move (rename) files

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:

  1. 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.
  2. 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
  1. 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
  1. 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 named file.txt to new_file.txt in the /home directory, you would run the following command:
mv /home/file.txt /home/new_file.txt
  1. 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
  1. 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