FactorPad
Build a Better Process

Linux rm Command Summary with Examples

Linux rm allows you to remove files or directories.
  1. Purpose - Learn what rm is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with rm.
  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 rm, 25 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 / rm-command.html


An ad-free and cookie-free website.


Examples of the Linux rm Command

Beginner

Learn to remove files and directories at the Linux command line.

Video Tutorial

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

Linux rm Command Summary with Examples (3:54)

Video Script

The Command and Why You Need It

Our twenty-fifth word, or command to memorize is rm from our category Navigation.

rm allows you to remove files or directories.

Common Linux rm Options
-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.

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 open the directory where we keep our stuff cd stuff and do a quick ls.

$ cd stuff $ ls extrastuff morestuff mystuff

Let's say we had second thoughts about how we'd like to organize this, so let's ls these directories.

$ ls * extrastuff: morestuff: video23.txt video24.txt mystuff:

Two empty directories. Okay, let's use rm -i to remove mystuff.

$ rm -i mystuff rm: cannot remove 'mystuff': Is a directory

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.

$ rm -irv mystuff extrastuff rm: remove directory 'mystuff'? y removed directory: 'mystuff' rm: remove directory 'extrastuff'? y removed directory: 'extrastuff'

And there's our reminder, are we sure? Yep. y and y.

$ clear $ ls morestuff

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.

$ mv morestuff/video24.txt .. $ rm -irv morestuff rm: descend into directory 'morestuff'? y rm: remove regular file 'morestuff/video23.txt'? y removed 'morestuff/video23.txt' rm: remove directory 'morestuff'? y removed directory: 'morestuff' $ ls $ ls .. stuff video11.txt video19.txt video21.txt video24.txt video05.txt video16.txt video20.txt video23.txt

A Final Tip

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.


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?

Subscribe to our YouTube Channel from here to get that one-two punch: video plus text. Check out the email list for reminders too.

Outline Back Tip Next

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


linux rm command
rm linux
remove directory linux
linux remove directory
linux delete file
rm command
delete directory linux
unix remove directory
delete folder linux
remove file linux
linux remove recursive
linux remove interactive
linux rm command syntax
linux rm summary
linux rm options
linux rm tutorial
unix rm
man rm
linux rm syntax
linux rm examples

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