There are few things as scary as the command
rm -rf. It deletes everything (it’s allowed to) without asking, recursively. Use it in the wrong place or on the wrong target and welcome to the “oh fuck” zone.
I don’t think I’ve ever had it run amok though, mostly because I don’t use the -f switch much. If something can’t be trivially deleted then it should ask me just in case. There are really damn scary stories out there about how bugs combined with
rm -rf can ruin stuff.
I don’t exactly know how I ended up in the situation I did. The root of all evil was a hardlink to a directory on my server. I thought Ubuntu didn’t allow that (my server runs Ubuntu too and I just tested locally that it doesn’t let me create one), but it was still there in my www folder, pointing at the folder that contained my blog’s stuff.
Yeah, past tense.
At least it seemed to be a hardlink, since it didn’t behave like softlinks I use all the time. For example, I couldn’t delete it. I tried unlinking it, but that failed and so did just
rming it. So I was there with a link I wanted gone, but I had no idea how to get rid of it.
Doing the mean command in the title, on the other hand, didn’t remove the link, but started deleting the contents (stupid to use that -r, right?) which is an awfully fast process for a tiny WP install.
Luckily the media uploads (at least most of them) appear to have been owned by the Apache user, so that stopped
rm there (and how lucky I wasn’t sudoing, huh?), and the rest could be replaced from a new WP download.
In retrospect I could’ve tried breaking the link by renaming the blog’s folder, but that didn’t even occur to me. Interestingly though,
rm -rf used on its parent folder did remove the link (without deleting any further contents from the linked folder).
I’m still not sure what exactly happened, but I pinky promise to be more careful in the future. In the meanwhile, enjoy a new WP theme.