Thursday, July 23, 2009

Taking Out The Trash Operating System

It is finally time to talk about one of the most hated design decisions (among many worthy candidates) of the Unix (and friends) operating system: irrevocable file deletion. You see, when you delete a file using, say, the rm command, it decides to simply delete all references to the file from the filesystem and mark the space as free. This means that, as far as Unix is concerned, the file is gone forever!

Modern operating systems, such as Tenex, have included a 'garbage can', so when you 'delete' a file, it goes into the garbage can, so if you accidentally deleted a file you need, you can go in there and get it back. Files are only permanently deleted if the user explicitly 'empties' the garbage can or the system needs more memory (at least this is how it works on Windows).

In a (mostly futile) attempt to be more user friendly, the GNOME and KDE devs looked at the trashcans every OTHER operating system used and decided to come up with their own half-assed implementation. Eventually, in an amazing display of cooperation, they even decided to standardize on the same directory, and people say Linux devs can't cooperate! Of course, since this functionality is not built-in to the operating system but is instead a matchsticks-and-glue implementation that rides on the Desktop environment, it has some problems.

First, it only works with programs that explicitly support it. Programs like rm or any GUI tool that is just a wrapper over shell tools (i.e. most of them) will still delete the files as usual. So, sometimes you can retrieve your important file, and sometimes you can't.

Second, since the trashcan is just a regular directory, it can quickly fill up, and if the user does not manually empty it regularly, the hard drive fills up as well. Just like an extremely lazy person, Linux doesn't take out the trash even if the whole house is filled with shit!

While writing my last article, I came upon an error when I quit Avidemux; it read something like "Unable to create Avidemux log. Filesystem is full." Leaving aside the fact that it was creating a log while it was exiting, this was worrisome. Well, I had been copying a lot of stuff onto the hard drive a few days ago, but I had deleted most of it. I then decided to open my garbage can and empty the trash. Lo and behold, 3 GBs of space opened up instantly!

Well, class, what have we learned today? First, not having a two-step deletion process can cause tens of millions of dollars of damage. Second, not integrating the trashcan leaves the user unsure if he can recover his files if he accidentally deletes them. Third, not monitoring the pseudo-trashcan means one can run out of space very quickly.

Class dismissed!


  1. You know, the windows command prompt "del" command doesn't send things to the recycle bin either. Just nitpicking though there is at least support for a true systemwide trashcan.

  2. So essentially, if you delete an important file which you have not backed up, that is the fault of the computer, not your own stupidity?... Right...

    I guess if you crash your car, that is the fault of the car for being too fast, not your own fault for being a shit driver?...

  3. Anonymous, Unix's problem is more like this Chinese truck, but, hey, it's only a problem if you crash!

  4. Well, I think recycle bins are just stupid. Maybe if they were invented on day 0 and implemented everywhere on the system level, they would make sense, but they are not. Linux, OS X and Windows implement them the same way, maybe on Linux less applications support those, and those that do, do it poorly, but that's pretty much it.

  5. Anonymous #1 is right. As much as I like reading about the fail that is Linux, you're doing it wrong. The Windows Recycle Bin is a shell-based extension, and not a kernel level feature.

    Keep the rants going, please. :)

  6. ... how about updating again anytime soon?

  7. Who on earth is this dick head? Paid by Micro$oft no doubt.

  8. The guy who said "You're doing it wrong" is now my biggest hero, because that just sums up the feelings I had while reading you're unbelievably inaccurate article (As usual).

    As someone else said, "del" in windows IS the same as "rm" in Linux. By the way, rm is NOT a Linux command but in fact a BASH command and anywhere you get a BASH shell, you get the "rm" command. Those who know what they are doing on a system (i.e. NOT YOU clearly) without a designated trash can, simply do "mkdir /trash && mv filename /trash" then when they're finished and have confirmed the folder contains nothing but useless files, "rm -Rf /Trash". This is the same principle in Windows and is the way things had to be done in DOS and early editions of Windows which did not include a Trash can at all either. As for the car analogy I'm guessing you drive an automatic, because if you accidentally don't use the clutch (mv filename /Trash) you might shatter your gearbox.

    As for filling up your hard drive, that is NOT a Linux only problem, I have spent SO much time over the years working with Windows, Linux and Macs emptying gigabytes of files out of peoples Trash to free up space on their hard drive.

    The tagline is thus, "If you don't know what you're doing with it, don't use the command line" and before you even think it, that rule applies to ALL operating systems with a command line, simulated (Windows) or not.

    Oh and before you post anything about how the filesystem handles deleting files again, you may want to actually find out how that works, it doesn't completely remove it at all, the rm command does exactly the same thing as the del command does, and the same thing as emptying the trash, it removes the pointer from the filesystem index, tricking the kernel into thinking there is free space on the filesystem and allowing it to overwrite files in an oldest first (In most cases) manner, it is actually possible to retrieve files from modern day filesystems, such as EXT2, 3 and 4, NTFS etc even after several formats in many cases, by using data recovery tools, so most enterprise organisations will do just that if they believe they may have caused "tens of millions of dollars of damage" by deleting things, not to mention MOST organisations with the potential to lose that much money with data loss TEND to have backup systems to prevent just that, if you're wondering what my qualifications on this subject are, I used to be a Data Forensics Engineer.

    Oh and if you run out of space very quickly these days, then you're too tight to go buy a decent sized hard drive, which doesn't exactly require a mortgage anymore.

    I could have said everything above in one word, IDIOT, but that wouldn't be as much fun.