mv Command: Tutorial & Examples

Move or rename files and directories

The mv command is a utility in Linux that allows you to move or rename files and directories.

Here is the basic syntax for using mv:

mv [options] source destination

The source argument is the name of the file or directory that you want to move, and the destination argument is the new location or name for the file or directory.

Here are some common options for mv:

  • -f: Forces the move and overwrites any existing files at the destination.
  • -i: Prompts the user before overwriting any existing files at the destination.
  • -v: Verbosely displays the names of the files that are being moved.

Here is an example of using mv to move a file named file.txt from the current directory to the /tmp directory:

mv file.txt /tmp

To rename a file or directory, you can use mv and specify the same directory for both the source and destination, like this:

mv file.txt newname.txt

This command will rename the file file.txt to newname.txt in the current directory.

It's worth noting that the mv command cannot move a file or directory across file systems. To move a file or directory to a different file system, you will need to use the cp command to copy the file or directory to the new file system, and then use the rm command to delete the original file or directory.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA