The biggest problem with RM is that it is impossible to restore the file by normal methods after deleting it. If the file is deleted by mistake due to hand shaking or Shell script error, it must be very troublesome.

Trash-cli is used to move files to the Recycle Bin and records the original address, delete date, and permissions of the file. Trash-cli uses the same recycling bin as the graphics file managers for KDE, GNOME, and XFCE. You can run Trash-cli on the command line or from a script. Project GitHub home page

Install and use the official Simplified Chinese README has been well written README_ZH-CN.rst

If you are a Debian family distribution, you can install it directly using APT

sudo apt install trash-cli

It can also be installed using Python PIP

pip install trash-cli

Method of use

Trash-put moves a file or directory to the trash bin. Empty the trash bin. Trash-list lists the trash bin file

Among them, the most important one is the Trash-Restore command, which is used by typing Trash-Restore first and then selecting the corresponding serial number from the list to restore the file.

Trash-put is a similar operation to the rm command, but it’s different. Rm removes directories with the -r argument, but Trash-put doesn’t. But despite that, Trash-Put supports input -R and other parameters, but only for compatibility with RM. Running Trash-Put-H gives you this explanation

Options: --version displays the program version and exits --h, --help displays this help information --d, --directory ignores (for compatibility with GUN RM) --f, --force ignores (for compatibility with GUN RM) -- I, --interactive ignores (for compatibility with GUN RM) -r, -r, --recursive ignores (for compatibility with GUN RM) -v, --verbose shows what this program does specifically

Should I alias Trash-Put instead of RM? That’s exactly what I did when I wrote this sharing post. But this is not officially recommended. One reason is that Trash-Put and RM syntax are not exactly the same, and there may be incompatibilities. Another is that the shell’s alias is only valid on the interface, not when run with a script. If this is forgotten, it may lead to trouble. Also, for people who use multiple shells, like me, I usually use ZSH, but sometimes revert to bash. If I don’t alias bash and ZSH at the same time, something might go wrong.

If you really want to use Trash-Put instead of RM, you can set the alias in your shell’s configuration file

# ~/.zshrc
alias rm="trash-put"

In some cases, if you don’t want to use Trash-Put in the interface, you can use slashes to de-alias

\ rm file name