How to move files that are older than 2 days

Does anybody know how to modify a script i run to grab all files older than 2 days?

Here is my current code

mv -f -u /mnt/test/* /mnt/test2 || mail -s "Scotts move has failed" scotts@cms-email.com < /dev/null

And I don't think that tmpwatch is the answer
LVL 1
shasta247Asked:
Who is Participating?
 
jlevieConnect With a Mentor Commented:
cd /mnt/test
find . -ctime +2 -exec mv {} test2 \;
0
 
shasta247Author Commented:
Excellent - thanks jlevie!
0
 
shasta247Author Commented:
do you know how to make the script email me if it doesn't find anything?
0
 
jlevieCommented:
I assume you mean if there weren't any files older than 2 days in /mnt/test. The shell script below should do that:

#!/bin/sh
cd /mnt/test
cnt=`find . -ctime +2 | wc -l`
if [ $cnt -gt 0 ]; then
  find . -ctime +2 -exec mv {} ../test2 \;
else
  echo "No files found older than 2 days" | mail -s "Scotts move has failed" scotts@cms-email.com
fi
0
All Courses

From novice to tech pro — start learning today.