Put files/folders you delete using rm into your Mac Trash Bin.

Praj Basnet
Nov 22, 2020

The following addition to your .bash_profile is super handy if you regularly use the command line/console on your Mac. Instead of simply deleting files forever it will instead put them into the .Trash folder in a unique sub-folder so you can recover them until you empty your bin. Very handy if you delete something by accident!

function rm () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
done
mv "$path" ~/.Trash/"$dst"
fi
done
}

--

--