FactorPad
Faster Learning Tutorials

Linux rm command summary with examples

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.
Paul Alan Davis, CFA, October 14, 2016
Updated: July 30, 2018
In this tutorial, 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 Next

~/ home  / tech  / linux essentials  / rm command


The Linux rm command

Beginner

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

Video Tutorial

Linux rm command summary with examples (3:54)

Videos can also be accessed from the YouTube Playlist.

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.

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.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the mv command, hit Back.
  • To switch gears to processing text with the wc command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / rm command



 
 
Keywords:
linux rm command
linux remove file
linux remove directory
linux delete file
linux delete directory
linux remove interactive
linux delete interactive
linux delete folder
linux remove recursively
rm linux
remove directory linux
linux rm tutorial
unix rm
man rm
linux rm syntax
linux rm examples