This is a script (function) to be added to a bashrc. The purpose is to not actually remove files, but rather to send them to a trash folder for safe keeping. I was tired of deleting important files. Because files may have the same name, I chose to create subdirectories with the date and file name on them, for easy access and to prevent conflicts.
Thoughts? Improvements I could make? This is my first BASH script function, and I'd love to make it a standard part of my computers, so I want to make it good first!
function rm {
PREFIX="~/.Trash";
for FILE in "$@" ; do
STARDATE=`date +%Y%m%d-%H%M`;
PLACE="${STARDATE}-${FILE}" ;
mkdir -p "${PREFIX}/${PLACE}";
mv $FILE $PREFIX/$PLACE/$FILE ;
echo "${FILE} moved to ${PREFIX}/${PLACE}" ;
done
}
$PREFIX/$PLACE/$FILEis not quoted. Also, why do you use${foo}instead of just$foo? \$\endgroup\$