FactorPad
Faster Learning Tutorials

Linux mv command summary with examples

mv allows you to move or rename files or directories.
  1. Purpose - Learn what mv is for and how to find help.
  2. Options - Review a few common options and examples.
  3. Examples - Walk through code examples with mv.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 14, 2016
Updated: July 30, 2018
In this tutorial, 24 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / mv command


The Linux mv command

Beginner

Learn to move and rename files and directories at the Linux command line.

Video Tutorial

Linux mv command summary with examples (4:23)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our twenty-fourth word, or command to memorize is mv from our category Navigation.

mv allows you to move or rename files or directories.

Recall from the last video (tutorial) we copied files around? Now we'll learn how to move those files around and change names.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The mv command has 14 options and two arguments, the first is the source and the second is the destination.

Like most commands, help is available here with double-dash --help.

The -i, or interactive mode will prompt you before overwriting files, as the dangerous default with mv is, like in cp just to overwrite the files silently.

And -u only moves the source when it is newer, like a backup.

So why is mv an important command? Well, mv allows you to customize files and directories to make them descriptive and useful. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go, let's do a quick ls, and the name of video5.txt here has been bothering me for a while.

$ ls stuff video11.txt video16.txt video19.txt video20.txt video21.txt video23.txt video5.txt

Let's do a mv -i of video5.txt, the source, and rename it video05.txt, the destination, keeping it in this directory.

$ mv -i video5.txt video05.txt $ ls stuff video05.txt video11.txt video16.txt video19.txt video20.txt video21.txt video23.txt $ clear

Oh good. Now when we do an ls it shows up in the proper order.

Next, let's dive in to stuff where we have three directories, with a cd stuff, then rename with mv yourstuff mystuff and then verify.

$ cd stuff $ ls extrastuff morestuff yourstuff $ mv yourstuff mystuff $ ls extrastuff morestuff mystuff

Ok. And then last let's move that file now in mystuff, with a mv -i mystuff/video23.txt over to morestuff.

$ mv -i mystuff/video23.txt morestuff/video23.txt mv: overwrite 'morestuff/video23.txt'? n

Oh look, -i worked, so let's recycle with the up arrow and instead I'll rename it video24.txt and move it at the same time.

$ mv -i mystuff/video23.txt morestuff/video24.txt $ ls morestuff mystuff morestuff: video23.txt video24.txt mystuff: $ _

A Final Tip

Okay now you know how to use mv. And you know the syntax for commands, options and arguments.

One last tip about the mv command. So now we know how to move, copy and make files, next we'll cover how we delete them.

Okay, thanks for visiting today. I hope this was a helpful introduction to the mv command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

If you'd like YouTube Channel reminders, click here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the cp command, hit Back.
  • To learn about the very important rm command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / mv command



 
 
Keywords:
linux mv command
linux move file
mv linux
rename file linux
linux move directory
linux rename file
move recursive
linux move tutorial
linux rename directory
unix mv
linux move interactive
linux rename interactive
mv recursive
move folder linux
man mv
linux mv syntax
linux mv examples