I have files with a date name ( 20060506 20060507 etc..) that i want to remove
because it keeps filling up the directory. Can someone please help me with a script to remove those date files. i would like to keep atleast 14 days worth from the current date. I hope i have explained it clearly and thanks :o
Can you do it based upon modification time instead of filename?
The below will remove all files in <dir> that have not been modified in the past 14 days.
find <dir> -mtime +14 -exec rm -f {} \;
will the below script of mine work this way?
#! /bin/sh
Today_Date=`date +%Y%m%d`
log=`/usr/TRS/HULFT/movedata.log`
mkdir /usr/TRS/backup/${Today_Date}
mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date} > ${log}
find /usr/TRS/backup/. -name 'T*' -mtime +1 -exec rm -fr {} \; > ${log}
The setting of the log variable line will give you an error using the `.
The rest looks ok. I would change would be the redirects on your log files. If you want a new log file everyday, then you can rm the logfile at the beginning of your script. The find command will work. I changed the search path a little, but your version should work as well. Your script will probably leave a bunch of directories, /usr/TRS/backup/<date>, out there. I would include something to clean that up. See below for the changes.
I hope this helps.
Mike
#! /bin/sh
Today_Date=`date +%Y%m%d`
log="/usr/TRS/HULFT/movedata.log"
#If you want a new log file on each run
rm -f ${log}
mkdir /usr/TRS/backup/${Today_Date}
mv /usr/TRS/data/T* /usr/TRS/backup/${Today_Date} >> ${log} 2>> ${log}
find /usr/TRS/backup -name 'T*' -mtime +1 -exec rm -fr {} \; >> ${log} 2>> ${log}
Hi Mike,
Thanks for the help. I think this shld work well. Many Thanks again =)
regards
wee