rm wrapper

Standard

Update1: You may want to try trash-cli / gvfs-bin instead of this script
Update2: You can also may want to look at idea #8217 to know some of the disadvantages of rm aliases


Sometimes when I run:
$ rm foo
I realize I didn’t mean it, so with this in my mind I made a little wrapper, now instead of removing my files, it sends them to the trash bin, it’s compatible with [nautilus|pcmanfm]. Example: If I run from a terminal $ rm img.png I can then go to the Trash carpet in Nautilus and restore it. If I delete it in Nautilus (by pressing the [Supr] button) I can open a terminal and type
$ rm -u img.png
If you want use the script, download it, move it to /usr/local/bin and add an alias to the ~/.bashrc file:
$ alias rm='rm_'
Hope it helps
About these ads

11 responses »

  1. Haven’t tried the script yet, but it really seems like a good idea! What about making it it’s own tool instead of just making it a wrapper script for rm?

    • Hi lkjoel, thanks for your feedback, the reason I used a wrapper is because I feel me more confident with bash scripting that with any other language, and I can’t think of any advantage in doing another tool.

  2. I would recommend using a different name in the alias, eg rid. This avoids embarrassment if you get used to the comfort of rm being ‘undoable’ and then type rm on some machine that does not have that alias.. oops!

  3. The ‘-l’ cmd lists the file path -> it would be nice to be able to revert a file using its file path:
    rm -u /home/user/myfile.txt

    This would solve two problems:
    – user can’t specify a single file, if multiple files with the same name exists in the trash
    – a file can’t be reverted using its file path

    I have to play around a bit longer with this script… like it so far.

    —————
    One thing where Ubuntu could really improve is to ship with an enhanced .bashrc and some scripts making the CLI a bit better/easier to use. For example I user a find-grep function to find a String recursively – printing some lines above and beneath the hit -> something like that could be useful for a bunch of people. Or just some aliases for often used cmd like: alias ai=’sudo apt-get install’ …

    • Hi Paradiesstaub, thanks for your comment, the rm wrapper can restore files using file path names, I’ve made a little test:

      $ mkdir 1 2 && touch 1/img.png 2/img.png
      $ ./rm_ 1/img.png 2/img.png
      $ ./rm_ -u
      /home/chilicuil/2/img.png
      /home/chilicuil/1/img.png
      Recover this items from trash? (Y/n) n
      $ ./rm_ -yu /home/chilicuil/1/img.png
      /home/chilicuil/1/img.png
      $ ls 1/img.png
      1/img.png

      It’s curious that it didn’t work in your system =(.., Respect to your other opinion, I think it would be a nice addon but I find it hard to add it to Ubuntu, I’m sure there a lot of people who would not like to learn new aliases or to permit that Ubuntu override the behavior of some cli tools.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s