Move Files and Folders on Linux

+------------------------------------------------------------------+
| Option | Description |
+------------------------------------------------------------------+
| mv -f | force mv by overwriting destination file without prompt |
| mv -i | interactive prompt before overwrite |
| mv -u | update - move when source is newer than destination |
| mv -v | verbose - print source and destination files |
| man mv| help manual |
+------------------------------------------------------------------+

Move a File from One Location to Another in Linux Using the mv Command

mv /home/source/demo.txt /home/destination mv - Move Command
/home/source/demo.txt - Source
/home/destination - Destination

Moving Multiple Files and Directories

mv source1 source2 destination
mv *.txt folder
If file2 exists and is a file, it will be overwritten.
mv -i file file2
If file2 exists and is a file, a prompt is given:
mv: overwrite 'file2'? y
mv -fi file file2
Same as mv -i. Prompt before overwriting. The f option is ignored.
mv -if file file2
Same as mv -f. Overwrite with no prompt. the i option is ignored.
mv -f  home/source/demo.txt home/destination
mv -n file file2If file2 exists and is a directory, file is moved into it. If file2 does not exist, file is renamed file2. If file2 exists and is a file, nothing happens.
For example:$ ls
b.txt c.txt d.txt geek.txt

$ mv -b geek.txt b.txt

$ ls
b.txt b.txt~ c.txt d.txt
mv --version

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store