Beginner · 6 min · practise every command in the built-in terminal

mv — Move and Rename Files

mv is used for both moving and renaming files.

Rename a file

mv oldname.txt newname.txt

Move a file to a directory

mv file.txt documents/
mv file.txt documents/newname.txt    # Move and rename at once

Move multiple files

mv file1.txt file2.txt documents/

Move a directory

mv olddir/ newdir/

No -r flag needed for directories with mv!

Useful flags

mv -i file.txt dest/    # Ask before overwriting
mv -v file.txt dest/    # Verbose output
mv -n file.txt dest/    # Never overwrite existing files

Important

Unlike cp, mv removes the original. There's no -r needed since you're just changing the location in the filesystem tree.

Practice tasks

  1. Rename README-backup.txt to old-readme.txt
  2. Move old-readme.txt into the documents/ directory
  3. Create a directory called myproject, then rename it to myproject-old
  4. Move a file into documents/ and rename it at the same time

Commands in this lesson

Files & Directories