Undergrad thought he had mastered Unix in weeks. Then he discovered rm -rf
theregister.com
theregister.com
--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. # rm -rf /*
</semi-sarcasm>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
rm -rf *
: and deleting everything from their Sun Workstation Unix account. Apologies!
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.
(headline needs to be fixed - article gives -rf as the option used not -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.
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
Try it yourself: https://infinitemac.org/1989/NeXTStep%201.0
alex@world RevelCode % echo ~
/Users/Alex
alex@world RevelCode % ls ~*
alex@world RevelCode %
I am also curious how `~*` expanded to an equivalent of `/users/*`.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 ~*
%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_NOMATCHcsh on NeXTStep 1.0:
localhost> echo ~
/me
localhost> echo ~*
echo: No match.Done.
Not sure how it got that way as I just copy / pasted the headline from the article. Autocorrect?
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.
With the tty restored, the rest was painful but doable.