IamCraig.com Rotating Header Image

November 26th, 2014:

Deleting files under Linux/Unix

Today I came across a comment on a blog post related to deleting files on a Unix/Linux system that was a clear case of bullshit. I tried to post a comment to that effect on the blog in question, but the comment feature was broken. So, since I had already gone to the trouble of writing my response, and since I don’t post nearly as much to my own blog as I would like, I’ll just post it here instead.

To PoorMe, who claimed to have “just lost all of [his/her] files and folders on [his/her] server in just 2 seconds” by running the suggested command, I call bullshit!

I actually intentionally tried this a few years ago on a server that I was decommissioning. First of all, you have to be in the root directory for the dreaded “rm -rf *” command to try and remove everything (unless you craft the command explicitly to remove everything under the root directory), and you’re almost never in the root directory unless you place yourself there for some specific and very unusual reason.

Secondly, in my test (which I did run as root) I ran into many files and directories that threw up errors and interrupted the process, even though I used the “-f” flag. In fact, I ended up having to delete individual directories off of the root to do what I was trying to achieve, and even then I gave up trying to remove anything but directories I knew contained user data.

Thirdly, even without those errors the process would have taken minutes, if not hours, not “2 seconds”. Anyone who thinks it takes two seconds has obviously never tried it. Besides, assuming you’re connecting over SSH, how are you still connected if you deleted everything, including the SSH server?

Bottom line, don’t run commands on your system that you find on the Internet without first understanding and checking them. But even if you don’t take that advice, the chances of you erasing every file and directory on your server in the blink of an eye are close to zero. Sure, you might erase a whole lot of stuff you didn’t want to erase that you may never get back and which may destabilise your system requiring you to reinstall the operating system (and it may happen in as few as two seconds), but what PoorMe claims happened almost certainly didn’t happen.