How to Move and Rename Files with the Linux mv Command

Published 2026-08-05 · Learn Linux

The mv command moves files from one place to another, and renaming is just moving a file to a new name. mv old.txt new.txt renames it, and mv file.txt backup/ moves it into a folder. This guide covers both uses and the safety flags.

Rename a file

Rename is a move where the destination is a new file name in the same folder.

$ mv notes.txt notes-2026.txt

Move a file into a folder

When the destination is an existing directory, mv places the file inside it, keeping the name.

$ mv report.pdf documents/

Move and rename in one step

Move into a folder and give the file a new name at the same time by writing both in the destination.

$ mv report.pdf documents/final-report.pdf

Avoid overwrites with -i

mv silently replaces a file with the same name. Add -i to be asked before overwriting, or -n to skip existing files entirely.

$ mv -i data.csv archive/

Move a whole directory

mv works on folders with no extra flags. mv project/ /var/www/ moves the entire tree. Add -v to see each move as it happens. See mv for the full reference.

Keep learning

Related guides: How to Copy Files and Directories with the Linux cp Command · The Linux ls Command: List Files Like a Pro · How to Find Files and Directories with the Linux find Command. Read all tutorials on the Learn Linux blog.