echo "-c copy the file rather than moving it"
echo "-d <dir> directory where the file should end up (default: .)"
echo "-h This help message"
+ echo "-m Use the file's modification time, not the current time"
echo
}
copy=0
destdir=.
-while getopts "cd:h" flag
+use_mtime=0
+while getopts "cd:hm" flag
do
case $flag in
c) copy=1;;
exit 1
;;
+ m) use_mtime=1;;
+
*) usage
exit 1;;
esac
[ -e "$file" ] || die "'$file' does not exist"
done
for file in "$@"; do
- new_file_name=$destdir/`date +'%Y-%m-%d'`_`basename $file`
+ if [ $use_mtime -eq 1 ]; then
+ new_date=`stat -c '%y' "${file}" | sed 's/ .*//'`
+ new_file_name="${destdir}/${new_date}_`basename "${file}"`"
+ else
+ new_file_name="$destdir/`date +'%Y-%m-%d'`_`basename "${file}"`"
+ fi
$cmd "${file}" "${new_file_name}" || die "failed on $file"
done