/ factorpad.com / tech / linux-essentials / mv-command.html
An ad-free and cookie-free website.
Beginner
Learn to move and rename files and directories at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux mv Command Summary with Examples (4:23)
Our twenty-fourth word, or command to memorize is mv
from our category
Navigation.
mv
allows you to move or rename files
or directories.
-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.
-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.
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.
Let's do a
mv -i
of
video5.txt
, the
source, and rename it
video05.txt
, the
destination, keeping it in this directory.
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.
Ok. And then last let's move that file now in
mystuff
, with a
mv -i
mystuff/video23.txt
over to
morestuff
.
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.
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.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
If you'd like reminders, make sure you connect on YouTube, Twitter and and with our no-spam email list.
cp
command,
hit Back.rm
command, click Next./ factorpad.com / tech / linux-essentials / mv-command.html
A newly-updated free resource. Connect and refer a friend today.