Introduction
The commandmvis one of the most used tools in the Linux command line to move and rename files and directories. Although its main function seems simple, understanding its options and behaviors avoids surprises, especially when working with absolute routes, symbolic links or different file systems.
Basic syntax
The simplest way ofmvfollows the pattern:
mv origen destino
Whereorigenis the file or directory you want to move anddestinocan be a new name (to rename) or an existing directory (to move it inside). Yeah.destinois a directory that exists,mvplace theorigenwithin him by retaining his original name.
Most commonly used options
-i(interactive): ask for confirmation before overwriting an existing file.-f(force): overwrites without asking, cancelling the effect of-i.-v(verbose): shows each operation performed, useful in scripts or debugging.-u(update): moves only when the origin is newer than the destination or when the destination does not exist.--backup=CONTROL: creates backup of the files that would be overwritten according to the specified mode (numbed, existing, simple, never).
Practical examples
Rename a file:
mv informe.txt informe_final.txt
Move a file to another directory:
mv foto.jpg /home/usuario/imagenes/
Move several files at once:
mv *.pdf documentos/
Use the interactive option to avoid accidental overwriting:
mv -i borrador.docx documentos/borrador.docx
Create a backup before overwriting:
mv --backup=numbered configuracion.cfg /etc/
Tricks and tips
When working between different file systems,mvcan behave as a copy followed by a deletion; therefore, in mounted units with optionsnoexecornosuidIt can fail. In such cases, usecpfollowed byrmIt's safer.
To rename directories that contain spaces in their names, you need to lock the route between quotes or use the escape with inverted bar:
mv 'proyecto antiguo' 'proyecto_nuevo'
In scripts, combine-vwith--backup=simpleallows to generate a clear record of which files were moved and which backups were created.
Finally, remember thatmvdoes not alter the permissions or extended attributes of the files; it retains the same that had the origin, unless the destination file system has different restrictions.
Conclusion
Domainmvis essential for any Linux user or administrator. Its simplicity hides a set of options that, when known, allow for safe and efficient file operations. Practice with the examples and options described will help you avoid common errors and make the most of this fundamental command.


