Skip to content

Instantly share code, notes, and snippets.

@habovh habovh/trash.sh
Last active Apr 3, 2016

Embed
What would you like to do?
Little trash script for use with OS X. Mimics Finder's behavior when deleting a file that has the same name as a file already present in the trash, with a bonus.
#!/bin/bash
for file in "$@"; do
filename=$(basename "$file")
extension="${filename##*.}"
filename="${filename%.*}"
dest="$HOME/.Trash/$filename.$extension"
if [ -f "$dest" ]; then
dest="$HOME/.Trash/$filename.$(date +%Y.%m.%d\ %H.%M.%S).$extension"
fi
mv "$file" "$dest"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.