Skip to content

Instantly share code, notes, and snippets.

@sksavant
Created July 5, 2013 20:02
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 sksavant/5936876 to your computer and use it in GitHub Desktop.
Save sksavant/5936876 to your computer and use it in GitHub Desktop.
Trashit
#!/bin/sh
# trashit
# original script
# http://www.macosxhints.com/article.php?story=20030217172653485
# author: Shane Celis <shane (at) gnufoo (dot) org>
#
# Sun, 20-May-2007; 06:47:22
# minor changes...
if [ $# -eq 0 ]; then
echo "usage: trashit <files...>" >&2
exit 2;
fi
for file in "$@"; do
# get just file name
destfile="`basename \"$file\"`"
suffix='';
i=0;
# If that file already exists, change the name
while [ -e "$HOME/.Trash/${destfile}${suffix}" ]; do
suffix=" - copy $i";
i=`expr $i + 1`
done
mv -vi "$file" "$HOME/.Trash/${destfile}${suffix}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment