The mv command stands for move which allows the user to move one or more files or files at once from one place to another in the file system. It can also rename files and folders and this command works without a confirmation message.
This command is built-in on Linux distributions. Now we’re gonna introduce you to using the mv command in Linux. Hope you understand.
The syntax of mv command
$ mv [option] source destination
Firstly, I will list the content contained in the current:
I have an example. Now I will rename the file test3.txt to mv.txt:
$ mv test3.txt mv.txt
Note: Be careful not to rename the file with an existing file because it will overwrite without notice.
We will have examples to understand this note. I will move mv.txt to test1.txt (exist):
1. -i (interactive): show overwrite confirmation message
Press y to yes, n to no. For example:
In this example, I pressed n because I don’t want to overwrite.
2. -n (no-clobber): prevent overwriting
As you can see, with this option, mv prevent overwriting of file test2.txt on test1.txt
3. -b (backup): back up an existing file
I overwrote the test2.txt file on test1.txt and the test1.txt file was backed up. That is the file ~test1.txt. The backup file will appear with the character (~) appended.
4. –version: check your version
$ mv --version
We just introduced you to how to use the mv command in Linux.
Thank you for reading!
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.