mv
Rename a file or folder, or move it somewhere else. One command does both.
>_ Try it: a simulated Linux, right herenothing runs on your computer
Loading the terminal…
Examples
-
mv todo.txt tasks.txt -
mkdir archive -
mv -v ideas.txt archive/ -
mv archive old-stuff -
ls old-stuff -
mv -n tasks.txt old-stuff/ideas.txt
How it works
mv renames and moves: mv old.txt new.txt renames the file, mv notes.txt archive/ moves it into the folder archive.
Unlike cp, nothing is left behind, and folders move without -r. Like cp, it replaces a file with the same name, so add -n when you want to be safe.
Syntax
mv [OPTION]... SOURCE... DEST
Options
| Option | What it does |
|---|---|
-v | say what was moved |
-n | never overwrite a file that already exists |
Good to know
- A slash at the end (
archive/) says "into this folder": if the folder doesn't exist you get an error instead of a file calledarchive. - To move several files at once, end with a folder:
mv a.txt b.txt archive/.