UNIX is a powerful system; when you tell it to do something, it does it. That's why people use GNU Linux and BSD and Solaris systems; they like being in control of their computer.

On the other hand, when a computer blindly does what you tell it to do, you'd better be sure you want to do it. Especially when you issue the dreaded "rm" command, which tells your computer to remove a file.

On the command line, there is no trashcan. If you tell a computer to remove a file, it removes the file, no questions asked. Sound like a bad idea? Sometimes it is! Happily, there is trashy, the sane and portable rm intermediary.

What Is trashy?

Trashy is a project that provides you with a trash command, which does two things:

Simple as that.

It is written in BASH but should be fairly portable and will run on any UNIX or UNIX-like system without additional dependencies to install.

How Do I Install?

  1. Currently you can grab trashy from its git repository by issuing this command:

    git clone git://gitorious.org/trashy/trashy.git

  2. Now all you need to do is install it. On Slackware or Fedora or Debian proper:

    cd ./trashy && su -c ./install.sh

    On Ubuntu or 0S X and some others:

    cd ./trashy && sudo ./install.sh

  3. And finally you might want to temporarily alias rm to trash because unless you're quite new to Unix, you probably have fingers trained to type "rm" when you really mean trash. To solve this, you can make an alias so that when you accidentally type rm, the file is trashed instead of deleted forever. On most Linux distributions you'd do this:

    echo "alias rm='/usr/local/bin/trash'" >> ~/.bashrc && source ~/.bashrc

    Note that this is a personal alias and will not interfere with the root user's usage of rm, but if you are still hesitant to interfere with such a low-level, common command, then at least alias rm to 'rm -i'

And that's all there is too it! No more accidental, irreversible deletion of files!

Note: Since sometimes you will probably really want to delete a file, you can always access the actual rm command by typing in the full path: /bin/rm (but use it sparingly; remember the reason you installed trashy in the first place was to avoid dangerous rm mishaps!)

How do I uninstall?

If you mean you want your unadulterated rm command back, you can do that by removing the alias:

sed -i 's_alias rm_#alias rm_' ~/.bashrc

But if you want to remove trashy entirely from your system then simply remove it, as it is a self-contained script:

su -c '/bin/rm /usr/local/bin/{trash}'

Can I Integrate trashy With KDE or GNOME?

By default, trashy uses the ~/.local/share/Trash directory. This means that if you are using the GNOME or KDE desktop, or any desktop that follows the Free Desktop spec, the file will automagically appear in your desktop trash can. You can even restore the files by right-clicking on the icon and selecting restore, because trashy follows the Free Desktop spec as closely as it can. (A future feature planned for trashy is the ability for it to restore files in the Free Desktop restore manner, but for now you would have to do that manually from the command line, or through the GUI.)

If you want to integrate it with some other trash can that does not follow the Free Desktop specification, you may be able to do that simply by changing the path of the trash can in the trash script.

GUI Integration on BSD, Solaris, and OS X

GNOME and KDE on BSD and Solaris function the same way, so integration is the same for them as it is with GNU Linux. OS X uses ~/.Trash as the location of its trash, and by default trashy should respect this. If it does not, you might need to make a change in the script. Of all the platforms, OS X is the least tested, because it is not a free operating system (either in cost or in freedom of choice) and so I do not use it often. However, when I do have an opportunity to test it on OS X, I do, and so far have not noticed any bugs.

I Love This But I Want More

Features requests, patches, and bug reports are always welcome. You can contact the author via the email addresses provided in the front matter of the Slackermedia book, or at the end of each GNU World Order episode.

I'm a Real Geek and I love rm. How dare you slander it.

If you love rm, continue using rm. I personally love rm; it's a very effective tool for instantly and permanently erasing a file from the face of this Earth and all possible worlds and timelines. For those who just want a little time apart from their files before eradicating them completely, there's trashy.

Trashy icon by liftarn at openclipart.org