Playing with fire: a devastating command line command (rm)
Tags: tutorial, commandline, productivity, bash
Published: 2019-08-21 05:27:50

---
title: Playing with fire: a devastating command line command (rm)
published: true
description: Today you'll see the most devastatingly powerful and perhaps even most exciting command line command of them all: rm.
tags: tutorial, commandline, productivity, bash
cover_image: https://thepracticaldev.s3.amazonaws.com/i/1yoxh2n57wk65p5l7ods.png
---

##Let’s talk about the most dangerous, powerful, and perhaps even most exciting command line command of them all: **rm.**

`rm` is shorthand for “remove.” At its core, `rm` allows you to delete things with unmatched precision and speed.

OK, great — so it removes things. Big deal, right? Can’t you just do the same thing with the trash can button? Why yes… yes you can. What makes `rm` terrifying, however, is that once you run that command, there is no “undo” button.

It’s gone forever.

When you read forum posts involving the `rm` command, battle-hardened devs will wisely open up their posts with sage, stern, and bold words of warning: **never run this command unless you know exactly what you’re doing with it.**

![rm command](https://thepracticaldev.s3.amazonaws.com/i/yr3dym3kk6758v2h7so8.png)


Now, to echo the wise and give my own sage and stern word of warning before I start this demo: _use `rm` sparingly and never run this command unless you know exactly what you’re doing with it._

###Seriously. `rm` should be used sparingly and soberly. 

(For this demo, we’re in a controlled environment; I also understand the risks involved, so let's proceed!)

Let’s say I want to remove one of these stubborn apps that insists it needs to stay on my machine because it’s an integral part of my operating system. Chess.app, really? Why don’t I believe you? I can’t drag and drop you to the trash — why? **You’ve got to go.**

![Chess app screenshot](https://thepracticaldev.s3.amazonaws.com/i/1yoxh2n57wk65p5l7ods.png)

No worries, `rm` is here to help.

Navigating to the Applications folder on the command line, we’ll then type: `sudo rm -rf Chess.app/`

And into dust it returns. 

###Here is what each command stands for:

- `sudo`= superuser do (gives you read/write/superpower abilities)
- `rm` = remove
- `-rf` = two flags smashed into each other for efficiency, `r` = “recursive” and `f` = “force.”

With `-rf`, we’re telling it to delete everything starting at that directory, working all the way down into its subfolders, subfolder subfolders, subfolder subfolder subfolders, and _alllllllllll_ the way down until everything is nuked into oblivion (recursive) without prompting for confirmation (force).

###Let’s do another one.

Say I have a bunch of files in a directory that contain the word “dorkasaurus” that are no longer needed. We'll type `rm`, then pass in our keyword contained by asterisks: `rm *dorkasaurus*`
Bye bye, all you dorkasaurus (but not “dorkasarus”) files.

![removing files](https://thepracticaldev.s3.amazonaws.com/i/o3lrczolagmishun1x64.png)

This command can be much faster than deleting files and directories manually. As you can imagine, this command and its assorted flags can also really mess up your system and ruin your week.

###Remember, there’s no undo button with `rm`.

One safe alternative you may consider using is a utility like [trash-cli](https://github.com/sindresorhus/trash-cli), which sends your files to Trash so you can manually delete them later.

Also, if you ever want to know what each command does along with its options, you can summon something called _manpages_ using the `man` command followed by the command you’re curious about. For example:

`man pwd`
`man ls`
`man rm`

![manpages](https://thepracticaldev.s3.amazonaws.com/i/281p2bxbu8ntr1d0v04y.png)


_manpages_ is essentially a guide explaining what each command and its flags do.

###In summary, `rm` is the most devastatingly powerful command line command that exists.

Whether you use “vanilla rm” or you use it in combination with flags 
such as `-rf`, it should always be used with caution rather than reckless abandon. If you’re going to experiment with it, consider using a Virtual Machine or some other computer where it’s OK to break things forever.

Happy hacking!

P.S. Follow me on [YouTube](https://www.youtube.com/realtoughcandy) where I talk a lot about cool web dev stuff:

<a href="http://www.youtube.com/watch?feature=player_embedded&v=AezH5ef1_3U
" target="_blank"><img src="http://img.youtube.com/vi/AezH5ef1_3U/0.jpg" 
</a>