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
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.
great.It’s a good way.
You may want to check gvfs-trash command from gvfs-bin package that interacts with Trash using the same specification as nautilus and various other applications that want to be good citizens – http://freedesktop.org/wiki/Specifications/trash-spec
Hi, thanks for your comment Roman, I didn’t know about gvfs-trash however it seems like it has no support for restoring from the cli: http://askubuntu.com/questions/162180/is-there-a-restore-counterpart-to-gvfs-trash , it seems like right now trash-cli is better suited for this job. I’ll suggest using them instead of this script.
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!
haha, I understand, as comments in idea http://brainstorm.ubuntu.com/idea/8217 say, it seems like it’s a better idea not to override rm behavior, the fact that it works for me doesn’t mean it may work with everyone. Thanks for your comment.
You could also just install trash-put instead, and make alias rm=trash-put; or as you do not care about the rm command-line options; just alias rm=gvfs-trash.
yep, I’ll recommend using trash-cli instead, thanks for your comment =)
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.