paritybit.ca

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e54048a00d63cd328db3d65219293c8110a1ed30
parent efee22bd889c58e0a77f26d84585b103dae05c1b
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Tue, 26 Nov 2019 17:49:39 -0500

Create new guide about rm and trash

Diffstat:
Apages/guides/using-rm-with-trash.md | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+), 0 deletions(-)

diff --git a/pages/guides/using-rm-with-trash.md b/pages/guides/using-rm-with-trash.md @@ -0,0 +1,52 @@ +## Using The "rm" Command With Trash + +[//]: # "This guide will show you how to make `rm` remove a file to the Trash folder first so that you can prevent yourself from accidentally irreversibly deleting something really important." + +[//]: # "base.min.css" + +[//]: # "Introduction; Bash and Bash-like Shells; C Shell and TENEX C Shell; Explanation" + +**Written By:** Jake Bauer | + **Posted:** 2019-11-26 | + **Last Updated:** 2019-11-26 + +### Introduction + +**Difficulty:** Beginner + +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") when it is +deleted. This allows them to restore that file in the case that they +accidentally deleted it. However, the story is different 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. In this +guide I'll demonstrate how to make `rm` remove a file to the Trash folder first +so that you can prevent yourself from accidentally irreversibly deleting +something really important. + +### Bash and Bash-like Shells + +(This also works in `fish` shell) + +<pre><code>alias rm='mv -t $XDG_DATA_HOME/Trash/' +alias rm!='\rm' +</code></pre> + +### C Shell and TENEX C Shell + +<pre><code>alias rm 'mv -t $XDG_DATA_HOME/Trash/' +alias rm! '\rm' +</code></pre> + +### Explanation + +The aliases above do the following: + +* Alias `rm` to `mv` where any files specified will be moved to the standard + trash folder instead of being deleted. +* Alias `rm!` to the normal `rm` program which effectively makes `rm!` a + "permanently delete this" command. + +If you don't have `$XDG_DATA_HOME` defined (which you normally would if you're +running a standard desktop like Gnome or KDE) you can replace that bit with +whichever path you prefer such as `$HOME/.Trash`.