FactorPad
Build a Better Process

Linux mv Command Summary with Examples

Linux 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.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux mv, 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 Tip Next

/ factorpad.com / tech / linux-essentials / mv-command.html


An ad-free and cookie-free website.


Examples of the Linux mv Command

Beginner

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

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux mv Command Summary with Examples (4:23)

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.

Common Linux mv Options
-options description
--help Print help screen
-i, --interactive Prompt before overwriting
-u, --update Move when source is newer

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 reminders, make sure you connect on YouTube, Twitter and and with our no-spam email list.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / mv-command.html


linux mv command
mv linux
linux mv examples
linux move directory
linux move file
linux move
rename file linux
move recursive
move interactive
linux mv how to
linux mv command syntax
linux mv summary
linux mv options
linux mv tutorial
unix mv
linux mv examples
linux mv syntax
man mv
move folder linux
mv recursive

A newly-updated free resource. Connect and refer a friend today.