8 # copyright Colin Patrick McCabe, 2011
18 echo "$0: archives old files"
20 echo "-c copy the file rather than moving it"
21 echo "-d <dir> directory where the file should end up (default: .)"
22 echo "-h This help message"
23 echo "-m Use the file's modification time, not the current time"
30 while getopts "cd:hm" flag
49 if [ $copy -eq 1 ]; then
55 [ -d "$destdir" ] || die "destdir '$destdir' is not a directory"
58 [ -e "$file" ] || die "'$file' does not exist"
61 if [ $use_mtime -eq 1 ]; then
62 new_date=`stat -c '%y' "${file}" | sed 's/ .*//'`
63 new_file_name="${destdir}/${new_date}_`basename "${file}"`"
65 new_file_name="$destdir/`date +'%Y-%m-%d'`_`basename "${file}"`"
67 $cmd "${file}" "${new_file_name}" || die "failed on $file"