Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to delete to trash from the shell in Ubuntu

📅 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
alias rm="echo Use trash-put or /bin/rm"
$ /bin/rm -rf dir_that_i_want_nuked

Tried with: trash-cli 0.12.10.3 and Ubuntu 12.04 LTS


© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email