Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been bitten a few times recently with rming things I shouldn't have - for example, forgetting to ulink symlinks, not rm them.

I'm thinking of writing a small bash script to simply move the target to ~/.local/share/Trash, as I haven't grasped restoring files (seems to involve a lot of Linux hackery that I'm not going to achieve any time soon).

The only problems I can think of are:

  • scripts/applications needing to rm files (really a problem? I could also get used to calling rm! or something),
  • files being moved to Trash while files there already have the same name (not sure how Ubuntu get's around that at the moment, could be fixed by appending md5(name + time()) to the name.

Of course the real answer's in backing up or just learning not to do silly things but I'd like an accommodating solution none-the-less.

Is this a really terrible idea or something that could be done?

share|improve this question
It's not a terrible idea, though as you note, backups are better. Perhaps the worst consequence is that you'll come to rely on the undo-able remove which may bite you when you aren't in a "protected" environment. Ubuntu backups are surveyed here:… – msw Sep 10 '10 at 17:33
up vote 11 down vote accepted

The 'significant disadvantage' is that you'll get used to rm not being the big nasty, use with extreme care tool it is. This means if you ever (in your whole life, so pretty likely) use another computer not set up with this 'soft-rm' then you may use rm more carelessly, forgetting your safety net is not there.

share|improve this answer
That's why you should name this command something else, such as delete or del for example. Something that will result in a "command not found" error where it isn't installed, thus no harm done. – Lars Haugseth Sep 14 '10 at 14:30

To install trash-cli, just type in a console:

sudo apt-get install python-setuptools
sudo easy_install trash-cli

Don't try to install trash-cli directly from the Software Centre or apt-get, the version there is old and has a bug that can lost the data moved to the Trash. The easy_install installer downloads directly from the project website, so you get a more recent version.

Ubuntu versions after 10.04 are not affected by this problem. You can just use:

sudo apt-get install trash-cli

You can alias rm to trash-put if you like, they have a compatible syntax. It works nicely with the gnome trash, you can recover files deleted from the command line with nautilus or the trash applet and restore files trashed from nautilus from the command line using trash-list.

It will take care of different files names and remember the original location of the files too.

You can also try gvfs-trash, as ændrük notes in the comments. But trash-put has a couple of advantages over gvfs-trash:

1) It's not tied to gnome or gvfs. It will work even on a server without gnome or in other desktop environment. It achieves gnome compatibility because it uses the freedesktop trash spec, as gnome.

2) It tries to use the same format as rm, so it can be aliased to it. It will not fail the first time that a script tries to trash-put -Rf dir

The main advantage of gvfs-trash is that it's installed by default in Ubuntu.

share|improve this answer
Is there any reason to use trash-put instead of gvfs-trash? – ændrük Sep 10 '10 at 16:24
First and most important: I didn't knew about gvfs-trash. Second: it's not dependent on gnome, it's compatible because it uses the freedestop trash standard. Third: it tries to keep option compatibility with rm so it can be aliased to it with minimal fuss, and this is the question. – Javier Rivera Sep 10 '10 at 17:09
I have added the non-humoristic reasons to the answer as I feel that they are important. Also the reference to gvfs-trash is important as it will be quite a better solution in most cases. – Javier Rivera Sep 10 '10 at 17:13
the first paragraph "Don't try to install..." seems to contradict the code block before it. I'm not trying to be a grammar wonk, it's just unclear. – msw Sep 10 '10 at 17:36
I'm not a native English speaker, and my grammar isn't exactly spectacular, so I appreciate any help in making it better. Please feel free to edit the post if you have enough rep, or just make a suggestion here. What I was trying to say is that you must install it using easy_install and not apt-get. – Javier Rivera Sep 10 '10 at 17:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.