For protection measures, add a recycle bin to rm

888u

Last update at :2024-05-19,Edit by888u


I believe everyone has used the "rm" command to delete files. Sometimes a shake of the hand will delete files that should not be deleted. So what should you do when you delete a file by mistake? Generally speaking, you will look for recovery tools. It has to be said that there are still many recovery tools under Linux, but these tools cannot 100% guarantee complete recovery.

It would be a better solution if we modify "rm" so that it no longer deletes files directly, but moves the files to the Recycle Bin. Of course, after we remove it, we still need to pay attention to the Recycle Bin to prevent the Recycle Bin from being accumulated by various junk files.

Here we share a script, which is hosted in Github and is suitable for both server and desktop environments. If the script detects a GNOME, KDE, Unity or LXDE Desktop Environment (DE) when running the "rm" command, it will safely move files or folders to the default trash $HOME/.local/share/Trash/files, otherwise The Trash folder $HOME/Trash will be created in your home directory.


The command to install the script is as follows (please install git first):

git clone https://github.com/lagerspetz/linux-stuff

sudo mv linux-stuff/scripts/saferm.sh /bin

rm -Rf linux-stuff


Set the alias in the .bashrc file,

aliasrm=saferm.sh


Execute the following command to make it effective,

source ~/.bashrc


Everything is ready, now you can execute the rm command to automatically move files to the Recycle Bin instead of permanently deleting them.



< /p>

For protection measures, add a recycle bin to rm

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码