Linux command list

mv command: move files and rename them

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying mv. Nothing here can touch your real files.
user@webterm:~/project$
 

mv moves a file, and renaming is the same operation seen from a different angle. Learn how moving within one directory becomes a rename, and how to avoid the silent overwrite, by running the commands in a real terminal in your browser.

Updated: 2026-09-05

Syntax

mv [options] source destination

The source is gone and it appears at the destination. If the destination is a directory the file lands inside it, otherwise that becomes its new name.

Try it first

The terminal on this page holds a few files and an archive/ directory.

$ ls
archive/  draft.txt  notes.txt  old.log  src/

Start with a rename.

$ mv draft.txt article.txt

Like cp, mv prints nothing when it works. ls shows that draft.txt is gone and article.txt is here.

$ ls
archive/  article.txt  notes.txt  old.log  src/

That is all a rename is: moving a file to a different name in the same directory.

Moving into another directory

Name a directory as the destination and the file goes inside it.

$ mv old.log archive/
$ ls archive
old.log

It is no longer where it was.

$ ls
archive/  article.txt  notes.txt  src/

You can move and rename in one step by writing both the directory and the new name.

$ mv notes.txt archive/notes.txt
$ ls
archive/  article.txt  src/

When you actually reach for it

mv is mostly how you fix where things live.

SituationWhat you type
Promote a draft to its real namemv draft.md release-notes.md
Sweep old logs out of the waymv *.log archive/
Move a config one level upmv config.json ..
Move without overwriting anythingmv -n notes.txt archive/

Things that trip people up

An existing file is overwritten silently. Just like cp, mv does not ask. -i prompts before replacing, and -n refuses to touch files that already exist.

A missing source is an error.

$ mv nope.txt archive/
mv: cannot stat 'nope.txt': No such file or directory

Either the name is misspelled, or you are not where you think you are.

How you write the destination changes the result. mv a.txt backup moves into backup when that directory exists, and renames the file to backup when it does not. Writing backup/ with the trailing slash keeps the intent explicit.

Practise it hands-on

webterm.appthis site

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.

See the course

Related commands

cp / rm / ls

Frequently asked questions

What does mv stand for?
Move. It moves a file somewhere else, and moving it to a different name in the same place is what renaming means here.
Is there no separate rename command?
Linux does have rename, but for a single file mv is what people use, because moving and renaming are the same operation.
What happens if a file with that name already exists?
It is overwritten without a prompt. Add -i to be asked first, or -n to leave existing files alone.
What is the difference between mv and cp?
mv leaves nothing behind, cp does. Use mv to fix where something lives, and cp to keep a copy before you change it.
Do I need -r to move a directory?
No. mv does not walk the contents, it just re-points the directory itself, so files and directories work the same way.