Using the “rm” Command with Trash
Those who use regular file browsers like Nautilus, Dolphin, or Thunar are used to having an item go into the Trash folder (or “Recycle Bin” for Windows folks) when it is deleted. This allows them to restore that file in the case that they accidentally deleted it. However, on the command line the
rm command will irreversibly delete a file from your system (short of using data recovery techniques) and has no concept of a Trash folder. This is a simple hacky way to make
rm remove a file to the Trash folder first so that you can prevent yourself from accidentally irreversibly deleting something really important.
POSIX, Bash and Bash-like, Fish, and Korn Shells
C Shell (csh) and TENEX C Shell (tcsh)
The aliases above do the following:
mvwhere any files specified will be moved to the XDG standard trash folder instead of being deleted.
rm!to the normal
rmprogram which effectively makes
rm!a “permanently delete this” command.
If you choose not to have
$XDG_DATA_HOME defined, you can replace that bit with whichever path you prefer such as
$HOME/.Trash. The folder you choose must already exist or else
mv will be angry.
This is my seventieth post for the #100DaysToOffload challenge. You can learn more about this challenge over at https://100daystooffload.com.