8

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?

Ross
  • 1,812
  • 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: http://ubuntu.stackexchange.com/questions/2596/comparison-of-ubuntu-backup-tools – msw Sep 10 '10 at 17:33

2 Answers2

14

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.

8128
  • 28,740
  • 2
    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
8

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

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.

8128
  • 28,740
Javier Rivera
  • 35,153
  • 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
  • @JavierRivera does the warning still apply? Or - to which version of the Ubuntu trash-cli package oues/did it apply? (note upstream has just released a version after long time) – Volker Siegel Oct 30 '14 at 01:29
  • Lucid (10.04), default install should be fine for later versions. – Javier Rivera Oct 30 '14 at 07:28