Undergrad thought he had mastered Unix in weeks. Then he discovered rm -rf

24 pointsposted 11 hours ago
by thesuperbigfrog

30 Comments

ashleyn

10 hours ago

The amount of times I've heard this story just makes me think rm was badly designed. Should not be this easy to nuke the entire system.

jerf

10 hours ago

It isn't anymore. From man rm:

     --preserve-root[=all]
         do not remove '/' (default); with 'all', reject any 
         command line argument on a separate device from its parent
The era of computing that the story claims to come from sounds like the late 1990s. By that time UNIX could have had that fairly easily; the resources were available. However at the time we were not that far off from the era where every byte counted, and there were a lot of people who had been programming for decades who were still in the mindset of "every byte is precious". In that era we still had the last few people running around claiming that writing code in anything other than straight, raw assembler was a waste of resources, though they were fading fast by that point. Anyone who has learned programming in an era of gigabytes may not understand just how expensive once upon a time even so much as a "nice error message" was, and every disk block of code that was going on to every system was a disk block unavailable for the user. UNIX used to be a lot sharper-edged than it is today.

mmh0000

8 hours ago

That's a lot of needless typing; when you need to uninstall something, you can still use globbing to work around that annoying error message:

  # rm -rf /*
</semi-sarcasm>

yjftsjthsd-h

4 hours ago

I'd give 2 responses depending on what you mean by that:

1. As sibling comment notes, at least GNU rm does make some effort to protect you.

2. I would suggest that any further protection is just going to get in the way. For example, I've run into systems that aliased rm to `rm -I`:

   -I     prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes
but I almost always promptly override that because sometimes yes I do actually want to delete a lot of files in a lot of places and I am not having this argument with the machine.

Or as has been put more elegantly:

“Unix was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.” — Douglas Gwyn

zubairq

10 hours ago

I remember trying to help a fellow student in Manchester University around 1991 and thinking I was deleting a subfolder when in fact I was in their home directory:

rm -rf *

: and deleting everything from their Sun Workstation Unix account. Apologies!

techjamie

8 hours ago

I went to clear some games off a drive to make room for new games, went to type RM -rf ./ and accidentally smacked enter instead of a slash. Wiped out a few games before I could stop it.

Got lucky there was nothing really important on there, and it didn't take long to fix things up. Fortunately, some stuff I was removing was at the top anyway.

bluGill

10 hours ago

I can't find any man page for rm that describes a -F option. In freebsd and GUN -R and -r mean the same thing. Can anyone help me?

(headline needs to be fixed - article gives -rf as the option used not -RF)

buran77

10 hours ago

> rm -rf ~*

I'm more curious about the ~* part. Is the behavior triggered by a tcsh peculiarity that no longer works that way these days? Why would ~* trigger he behavior of deleting every home directory?

And aren't Emacs backup names appended with ~ rather than prepended? In that case shouldn't it be "~" (anything ending in ~) instead of "~*"?

The story sounds a bit flimsy regardless. Not that it's improbable but rather the opposite, rm -rf* stories are a dime a dozen.

matrss

10 hours ago

~username expands to the home directory of username. There might have been a shell that likewise expanded ~* to all home directories.

andai

10 hours ago

Here's my reading: this ran in /home/ for some reason, where all the homedirs had a name pattern like ~stuff.

MayeulC

10 hours ago

Likewise. Quite a few people here not realizing this is likely (t)csh-specific.

I ran a quick test on multiple tcsh versions I had installed, the oldest being 6.13 (2004, RedHat 4). All returned 'Unknown user: *.'

It wouldn't surprise me if at some point this expanded to every user's home directory, the way '~username' expands to /home/username, or wherever that user's home is.

I couldn't find anything of note in https://github.com/tcsh-org/tcsh/blob/master/Fixes

einr

10 hours ago

I couldn't say for sure that some UNIX shell somewhere at some point did not do home directory wildcard expansion -- seems like a WMD grade foot gun, but OK -- but as you've noticed, tcsh does not do it and in fact even if you go back to csh in NeXTStep from 1989 it doesn't do it either.

Try it yourself: https://infinitemac.org/1989/NeXTStep%201.0

TrainedMonkey

10 hours ago

On zsh `~` expands to home directory, while `ls ~*` does not do anything:

  alex@world RevelCode % echo ~
  /Users/Alex
  alex@world RevelCode % ls ~*
  alex@world RevelCode %
I am also curious how `~*` expanded to an equivalent of `/users/*`.

einr

10 hours ago

It does not "not do anything", it expands to a list of your files that have a filename starting with ~. You just don't happen to have any in the current directory ;)

And yes, this is a potential footgun:

  % touch ~test
  zsh: no such user or named directory: test
  % touch "~test"
  % ls ~*
  ~test
  % rm ~test
  zsh: no such user or named directory: test
  % rm "~test"
  % ls ~*     
  %

mmh0000

8 hours ago

It partially depends on Zsh's NOMATCH and NULL_GLOB setopt:

NOMATCH - print error when glob doesn't match;

NO_NOMATCH - print literal GLOB character:

  setopt NOMATCH
  ls * => zsh: no matches found: *

  setopt NO_NOMATCH
  ls * => ls '*'
NULL_GLOB - when glob doesn't match, return blank; (Overrides NOMATCH):

  setopt NULL_GLOB
  ls * => ls ''

  # Brings behavior inline with RHEL/Bash4 defaults:
  setopt NO_NOMATCH

account42

10 hours ago

It kind of makes sense that if you have ~username and wildcards that you can then apply those wildcards to the username as well and not just real files and directories.

blakesterz

10 hours ago

My first thought was wanting to get rid those files that emacs leaves behind.

user

10 hours ago

[deleted]

justin66

10 hours ago

Recursively remove everything in the home directory.

einr

10 hours ago

No, that would be ~/* or just ~. The article says that the command deleted every user's home directory, which seems to imply that the shell would expand ~* to a list of every user's home directory. But -- sensibly -- neither modern tcsh, bash, zsh, ksh nor the ancient csh in NeXTStep does that.

csh on NeXTStep 1.0:

  localhost> echo ~
  /me
  localhost> echo ~*
  echo: No match.

ruthmarx

9 hours ago

I don't think the tilde is referring to a shortcut for a home directory here, rather I think it's the first character in the filenames of the backup files he was trying to delete.

thesuperbigfrog

10 hours ago

>> (headline needs to be fixed - article gives -rf as the option used not -RF)

Done.

Not sure how it got that way as I just copy / pasted the headline from the article. Autocorrect?

tarboreus

5 hours ago

I remember someone trying to fix an isue on my machine recursively changed all permissions on the whole drive to 777. Might as well have nuked the system.

zehaeva

10 hours ago

I always thought that such things were an urban legend of unix/linux environments. "Be careful with your commands! You too could nuke your entire installation!". When I was in college (some 20 years ago) I rolled my eyes every time I heard some old timer wag his finger and recount of sometime some new hire managed to destroy days/weeks/months of work by running rm -rf.

And then, one day, at work I was advising a junior engineer. He were having issues with a software build process that he was tasked with documenting. I explained what went wrong, what he can do to correct for that, and to try again. He said okay and while I stood there, looking over his shoulder, typed rm -rf . and hit enter faster than I could shout "NO!".

I just stood there and laughed for a good 5 minutes before I was able to catch my breath and explained to him why his machine was unresponsive.

PeterWhittaker

9 hours ago

Been there. Thought I was in a subordinate directory, forgot I was in /dev. When my tty went funky, I realized the scope of my error, hit ctrl-C, and with great luck managed to remember the mknod incantation for tty.

With the tty restored, the rest was painful but doable.

QuesnayJr

10 hours ago

The title alone is a horror story in two sentences.

felixnm

10 hours ago

Right? I cringed when I read it.

user

10 hours ago

[deleted]