When organizing files in a graphical desktop environment, you typically “Cut” a file from one folder and “Paste” it into another. In the Ubuntu Linux terminal, this action is accomplished using the mv command (short for “move”). The mv command physically relocates the file from its source directory to a new destination, leaving nothing behind. Crucially, the mv command is also the official way to rename files in Linux.
The Basic Syntax of the mv Command
The mv command requires two arguments: the source (what you want to move) and the destination (where you want it to go).
mv [source] [destination]
Moving a File to a Different Directory
The most common use of mv is relocating a file from your current folder to another folder. For example, if you downloaded a file named invoice.pdf and want to move it into your Documents folder:
mv invoice.pdf /home/username/Documents/
The file is instantly transported to the Documents folder and is no longer present in your current directory.
Renaming a File (Moving it to the Same Place)
In Linux, there is no dedicated “rename” command for basic file editing. Instead, you simply “move” the file into its exact same location, but give it a different name.
If you have a file named old_report.txt and you want to rename it to new_report.txt, you type:
mv old_report.txt new_report.txt
The file never actually moves anywhere; the system just updates its name label.
Moving and Renaming at the Same Time
You can combine both actions in a single command. If you want to move draft.docx to your Documents folder and rename it to final.docx during the transit, you specify the new filename at the end of the destination path.
mv draft.docx /home/username/Documents/final.docx
Moving Multiple Files at Once
If you need to move a batch of files into a folder, you can list all the source files first, followed by the destination directory at the very end. The destination must always be the last item in the command.
mv photo1.jpg photo2.jpg photo3.jpg /home/username/Pictures/
You can also use wildcards. To move every single MP3 file in your current folder over to your Music folder, use the asterisk (*):
mv *.mp3 /home/username/Music/
Important Warning: Accidental Overwrites
Like the cp (copy) command, the mv command is silent and assumes you know exactly what you are doing. If you move a file into a directory that already contains a file with the exact same name, mv will instantly overwrite the existing file and permanently destroy the old data.
To prevent this, you should always use the interactive flag (-i) when moving important files. This forces Linux to ask for confirmation before destroying any existing data.
mv -i invoice.pdf /home/username/Documents/
If a file named invoice.pdf already exists there, the terminal will pause and ask: mv: overwrite '/home/username/Documents/invoice.pdf'?. Type y to overwrite it, or n to cancel the move.