/ factorpad.com / tech / linux-essentials / rm-command.html
An ad-free and cookie-free website.
Beginner
Learn to remove files and directories at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux rm Command Summary with Examples (3:54)
Our twenty-fifth word, or command to memorize is rm
from our category
Navigation.
rm
allows you to remove files or
directories.
-options | description |
---|---|
-i ,
--interactive |
Prompt before each removal |
-r
-R
--recursive |
Remove directories and their contents |
-v
--verbose |
Explain what is being done |
Recall from the last video (tutorial) we moved files around? Now we'll learn how to delete them.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The rm
command has
12 options and arguments are the files or directories
you'd like to delete permanently.
Like most commands, help is available with double-dash
--help
.
Just as with cp
and
mv
before it, the
-i
, or interactive mode, will
prompt you before removing files. The default is to delete silently
with the rm
command.
Also to delete directories, you'll need the
-r
, recursive option, and with
-v
you see confirmations of actions
being performed.
So why is rm
an important command?
Well, rm
is required to delete
unwanted stuff.
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 open the directory where we keep our stuff
cd stuff
and do a
quick ls
.
Let's say we had second thoughts about how we'd like to organize this,
so let's ls
these directories.
Two empty directories. Okay, let's use
rm -i
to remove
mystuff
.
Oh yeah, we need -r
to remove
directories. Hey, while we're at it,
let's delete two at once and include
extrastuff
with
-irv
.
And there's our reminder, are we sure? Yep.
y
and
y
.
Very good. Gone forever.
And last, let's move video24.txt
back
up one directory and remove morestuff
as well using rm -irv
again just to
be sure.
Okay now you know how to use rm
.
And you know the syntax for commands, options and arguments.
One last tip about the rm
command.
Because rm
is such a potentially
harmful command, I suggest habitually including the
-i
option. And look at that 25 commands
down, one-quarter of the way through. Very good.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the rm
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Subscribe to our YouTube Channel from here to get that one-two punch: video plus text. Check out the email list for reminders too.
mv
command,
hit Back.wc
command, click Next./ factorpad.com / tech / linux-essentials / rm-command.html
A newly-updated free resource. Connect and refer a friend today.