Skip to content

Instantly share code, notes, and snippets.

@habovh
Last active April 3, 2016 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save habovh/a2a430eb67e67efec712b85f7be4e310 to your computer and use it in GitHub Desktop.
Save habovh/a2a430eb67e67efec712b85f7be4e310 to your computer and use it in GitHub Desktop.
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