The Linux move command, or short mv
, is a Linux/Unix command-line tool used for moving or renaming files and directories depending on the arguments used. It gives the user the ability to move single or multiple files, rename files, and even prompt you before overwriting a file. In this tutorial, we will discuss the Linux Move Command mv
and how you can use it to move or rename your files or directories.
Table of Contents
- How to move a file from one directory to another
- Move multiple files from one directory to another
- Use pattern matching to move files
- Move a directory to another
- How to prompt before overwriting a file
- Move files newer than the destination
- View Verbose output when moving files
- How to rename files using the Linux move command
- View more options about the Linux mv command
- Conclusion
How to move a file from one directory to another
To move a file from one directory to another, use the syntax:
Code language: Bash (bash)mv filename /directory/path/
For example, to move a file file1.doc to the directory /root/docs/ execute the command:
Code language: Bash (bash)mv file1.doc /root/docs
The command moves the file entirely from its current directory to the directory defined as /root/docs/. You can confirm the existence of the file in its new location by running the ls command as shown:
Code language: Bash (bash)ls -l /root/docs/

Move multiple files from one directory to another
To move multiple files from one directory to another, use the syntax:
Code language: Bash (bash)mv file1 file2 . . . /directory/path/
For instance, to move 3 files, file1.txt, file2.txt,
and file3.txt
to /root/docs
run the command
Code language: Bash (bash)ls file1.txt file2.txt file3.txt /root/docs/
Use pattern matching to move files
Moving multiple files one by one can be a tedious task. The Linux move command has made it a whole lot easier to move multiple files which share the same file extension.
In the previous example, if you want to move all the files which have the .txt extension, use the wild card symbol as shown:
Code language: Bash (bash)mv *.txt /root/docs
Move a directory to another
When moving directories, the syntax remains pretty much the same as when moving files. The syntax for moving a folder or directory to another is:
Code language: Bash (bash)mv folder /destination_directory
For example, to move the docs
directory to /reports
directory, run the command:
Code language: Bash (bash)mv docs /reports

To confirm, run
Code language: Bash (bash)ls /reports

How to prompt before overwriting a file
When you move a file to another directory with the same file name, the destination file will usually be overwritten. However, you can use the -i
option with mv command to prompt you whether or not to overwrite the file. This will prevent accidental overwriting of a file.
Code language: Bash (bash)mv -i file1.txt /reports/docs
To go ahead with overwriting the file, type Y (for Yes) and hit ENTER.
If you wish to cancel the operation, simply Type N (For No) and hit ENTER.
Move files newer than the destination
Sometimes, you may need to update files in the destination directory. To do so, use the -u
flag
Code language: Bash (bash)mv -u file1.txt /reports/docs/
View Verbose output when moving files
The Linux move command can allow you to have a glimpse of the ongoing process using the -v option. To view the files being moved use the syntax:
Code language: Bash (bash)mv -v file_name(s) /directory/path
For example,
Code language: Bash (bash)mv -v file5.txt file6.txt /reports/docs/
How to rename files using the Linux move command
Aside from moving files, the mv
command can be used to rename files. This happens only and only if the source and destination directory of the original and renamed file is the same.
For instance to rename a file CentOS_tutorials.doc
to Ubuntu_tutorials.doc
run the command
Code language: Bash (bash)mv CentOS_tutorials.doc Ubuntu_tutorials.doc

View more options about the Linux mv command
We have covered the main usages of the Linux mv command. However to quench your curiosity about more options that are used with the command, open the man pages for the command by running
Code language: Bash (bash)man mv

Conclusion
And with that, we come to the end of this tutorial. It’s our hope that you can now move and rename files on your Linux system without any difficulty.
Check out other tutorials over in the Linux category! If you want an easy Linux distro to get your feet wet, I always recommend Ubuntu.