Skip to content

Instantly share code, notes, and snippets.

@rtud
Last active December 19, 2015 11:28
Show Gist options
  • Save rtud/5947543 to your computer and use it in GitHub Desktop.
Save rtud/5947543 to your computer and use it in GitHub Desktop.
Bash Function to be inserted in .bash_profile or .bash_alias, that moves the files/folders to the systems Trash. Use it instead of <rm> for a peace of mind.
# Move to trash
trash() {
yellow=$(tput setaf 3)
reset=$(tput sgr0)
echo -e "\n"
for f in "$@"; do
bn=$(basename "$f")
while [ -e ~/.local/share/Trash/files/"$bn" ]
do
bn="$bn $(date +%H.%M.%S %p)"
done
if [ -d "$f" ]
then t='Directory'
else t='File'
fi
mv "$f" ~/.local/share/Trash/files/"$bn"
echo -e "$t ${yellow}$f${reset} moved to Trash."
done
echo -e "\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment