After deleting some files I didn't want to , I decided to protect myself by aliasing rm to a "rmv" function I wrote and placed in my local bin. Basically, I want rmv to copy whatever folder or file is being deleted to my trash folder, then remove the folder or file. Further, I would like rmv to accept the following flags:
-f = do not copy folders/files to trash, just delete
-i = interactive mode
-v = verbose
Code for the function is as follows:
for a in "$@"
if[-f "$a"] ; then
/bin/rm -rf "$@"
elif[-i "$a"] ; then
cp -ri $a /path/to/trash/folder
/bin/rm -ri $a
elif[-v "$a"] ; then
cp -rv $a /path/to/trash/folder
/bin/rm -rfv $a
elif[-* "$a"] ; then
echo "Unexpected flag in call to rmv.\n"
cp -r $a /path/to/trash/folder
/bin/rm -rf $a
I know its far from perfect, but hopefully enough for a BASH expert to get the idea and tell what all I've done wrong. Also, I'm not worried about overwriting files of the same name. The trash folder is basically there just to catch my typos when using rm.