mv (move) is a Unix command that moves one or more files or directories from one place to another. It is also used to rename a file/folder.
In this article we will discus different examples of mv command.
Move a file or Directory
So, use below command to move your file from one place to another.
ls
mv file-name destination-path
In below example, I have moved a file “abc.txt” to a test folder placed in / path.
mv abc /
ls /
you can see example in below image
Move Multiple files
So, if you want to move multiple files into a directory in a single command, issue the following.
ls
mv file-one.txt file-two.txt file-three.txt /test
ls
you can see example in following image
Rename a File or Directory
Let say we have a file called exp.txt and we want to rename it as “demo.txt” then we will use following command
ls
mv exp.txt demo.txt
ls
Now you can see in below image that exp.txt file has been renamed with demo.txt
Now rename a directory test with testnew
ls
mv test testnew
ls
And that is it.