📅 2013-May-01 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ rm, trash-cli, ubuntu ⬩ 📚 Archive
The rm command is probably the most dangerous command to use from the shell in Linux. Deleting files and directories at the shell is a common task we do all day. But, one small mistake with rm can lead to disaster since it is hard to recover those deleted files. The question that begs then is: why not safely delete to the trash can, just like we do on the desktop?
Thankfully, that is possible thanks to trash-cli. It has commands to move files and directories to the trash can on your Ubuntu desktop.
Here is how I have set up my system to delete files to trash from the shell:
$ sudo apt install trash-cli
$ trash-put foobar.txt *.doc
trash-put is a long command name, I have added an alias to my ~/.bash_aliases file that maps this command to a shorter name: can.
Finally, you need to protect yourself from accidentally typing
rm and losing files. And you need to be reminded to use
trash-put whenever your finger memory types
rm. To do this, create an alias in ~/.bash_aliases named
rm that reminds you not to use it:
alias rm="echo Use trash-put or /bin/rm"
rm, it is still around. Use its full path to invoke it:
/bin/rm. For example:
$ /bin/rm -rf dir_that_i_want_nuked
rmthat maps to
trash-put. I have been burnt by this mistake! What happens is that you might need to switch to a new computer or a colleague’s computer for a short task and your finger memory types
rmthere thinking the files are going into the trash can.
Tried with: trash-cli 0.12.10.3 and Ubuntu 12.04 LTS