Skip to the workspace
Pebellslearn by building
Navigation Basics  ›  Lesson

mv — Moving Files and Directories

Moving Files / Directories 12 minmv takes the thing first and the destination second, moving into an existing directory, renaming to a new name, or overwriting an existing file.

linux / mv — Moving Files and Directories

Explore each scene at your own pace.

01 · The rule

The rule

mv — Moving Files and Directories

Asha's garden photos keep landing in her home directory, and last month's notes are sitting in the wrong folder. On the command line there is no dragging with a mouse. One command moves things, and the same command renames them.

The rule

mv takes the thing first, then where it goes.

The shape is always:

mv SOURCE DESTINATION

What happens depends on the destination:

  • If the destination is an existing directory, the source moves into it and keeps its name.
  • If the destination does not exist, the source is renamed to that name.
  • If the destination is an existing file, it is replaced, silently, with no warning.
$ cd ~/garden
$ mv ../tomato.jpg plots/          # moves into plots, still called tomato.jpg
$ mv notes.txt june-notes.txt      # renames in place
$ mv plots beds                    # renames a whole directory

Moving a directory needs no special option. mv doesn't copy anything; it just changes where the name points, so the whole folder goes along, whatever it contains.

You can move several things at once. When you give more than one source, the last argument must be a directory:

$ mv tomato.jpg basil.jpg chilli.jpg plots/

Two safety options are worth learning now:

  • mv -i (interactive) asks before it overwrites a file that already exists.
  • mv -n (no-clobber) never overwrites. It just skips that file.
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.