How to Move Files or Folders with mv command in Ubuntu with examples

This brief tutorial shows students and new users how to use the mv command in Ubuntu to move or rename files and directories.

On Linux systems, including Ubuntu the mv command can be used to move or rename files and directories. It is also commonly used when creating a backup of existing files and folders.

If you’re a student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.

Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.

About the mv command:

The mv command moves or renames files and folders on Linux systems, including Ubuntu. If you use the -b or –backup options, the mv will rename the destination file if it exists, appending a suffix to its file name. this prevents overwriting existing files.


The syntax is the rule and format of how the mv command can be used. These syntax options can be reordered, but a straight format must be followed.,.

Below is an example syntax of how to use the mv command.



The command line options are switches or flags that determined how the commands are executed or controlled. they modify the behavior of the commands. they are separated by spaces and followed after the commands.

Below are some options for the mv command:

  SOURCE Replace SOURCE with the source of the file or folder
 DESTINATION Replace DESTINATION with the destination of the file or folder
  –backup[=CONTROL]   If you use the -backup option, mv make a backup of each existing destination file
     -bUse the -b mv behaves like –backup but does not accept an argument
    -f, –forceUse the -for –force, mv does not prompt before overwriting existing content
    -i, –interactiveThe -i or interactive option, mv prompts before overwriting existing content
     –helpDisplay a help message and exit.

If you use the -b or –backup options, mv will rename the destination file if it exists, appending a suffix to its file name. This saves a copy of the original file instead of overwriting it.

For example, if you want to rename a file called myfile.txt to myprivate.txt, simply run the commands below:


mv myfile.txt myprivate.txt

The command above moves or deletes myfile.txt and creates a new file with a content called myprivate.txt

If you wish to move myfile.txt into a different directory in your home folder called private, simply run the commands below:


mv myfile.txt /home/private

The command above moves myfile.txt into the specified directory called private inside your home folder.

The -f option forces the mv command to overwrite the existing file with the same name in the destination without prompt.

mv -f myfile.txt /home/private

When you use the -I option, the mv command prompts before overwriting existing files with the same name.

mv -i myfile.txt /home/private/

If there’s already a file called myfile.txt inside the /home/private directory, a prompt is given:

mv: overwrite '/home/private/myfile.txt'?

Entering "y", "yes", "Yes", or "Y" will result in the file being overwritten

When you use the -b or –backup option, the mv command makes a copy of the existing file.


mv -b myfile.txt /home/private

If myfile.txt exists in the /home/private, the existing copy will be renamed to


For moving directories, simply provide the source directory and the destination:


mv secrets /home/secrets

You can use many more complex options with the mv commands, but the few above will get you started with how to use the mv command on Ubuntu.


This post shows you how to use the mv command on Ubuntu to move or renew files and directories. If you find any error above, please comment below to alert us.