1. Install TRASH-CLI
sudo apt-get install trash-cli
2. Set up the script
sudo gedit/usr/local/bin/trash-rm
Copy
#!/bin/bash
# command name:trash-rm
shopt-s extglob
recursive=1
declare-a cmd
((i = 0)) for
F In "$@" does case
"$f" in
(-* ([Fiiv]) r* ([Fiiv]) |-* ([Fiiv]) r* ([Fiiv]))
tmp= "${f//[rr]/}"
if [-N " $tmp "]
then
#echo" \ $tmp = = $tmp "
cmd[$i]=" $tmp "
((i++))
fi
recursive=0;;
(--recursive) recursive=0;
(*)
if [$recursive! = 0- D "$f"] then
echo "Skipping directory: $f"
continue
else
cmd[$i]= "$f"
((i++))
fi;
Esac
done
trash "${cmd[@]}"
Update:starting with Ubuntu 12.04 precise pangolin, TRASH-CLI provides the command "Trash-put" to trash files, instead o F the previous "trash" command, so in the ' code above, on the last line, replace ' trash ' with ' trash-put ' for Ubuntu 12.04 + .
Then
sudo chmod +x/usr/local/bin/trash-rm
3. Create an alias for "RM" to use "TRASH-RM"
Gedit ~/.BASHRC
Alias rm= "Trash-rm"
Bash
4. Final TRASH-CLI Tips
Trash-empty Empty the Trashcan (s).
Trash-list list trashed file.
Restore-trash restore a trashed file.