Please help me to write the script

Hi All,

I have written the follwing script to take the backup of the file every day
along with the date.

DATE=`date +%Y%m%d`

export DATE

cp var/hr/hr333m.txt cp var/hr/payments/hr333m_$DATE.txt

The file name as follows after taking the backup.

hr333m_20110630.txt

Could you please help me to remove the backup file,if it is 7 days old compared to the server date.

Thanks in advance.

find var/hr/payments/ -mtime +7 -exec rm -f {} \; 

Thanks for your reply

Suppose the files are as follows in the path var/hr/payments/

abcd.txt            created on Jun 30 
hrm.txt             created on Jun 30
hr333m_20110630.txt created on Jun 30
hr333m_20110630.txt created on Jun 30
hr333m_20110629.txt created on Jun 29
hr333m_20110628.txt created on Jun 28
hr333m_20110627.txt created on Jun 27
hr333m_20110626.txt created on Jun 26
hr333m_20110625.txt created on Jun 25
hr333m_20110624.txt created on Jun 24
hr333m_20110623.txt created on Jun 23
hr333m_20110622.txt created on Jun 22

If we raun the following query on 6 th Jul 2011

find var/hr/payments/ -mtime +7 -exec rm -f {} \;

All the files with 7 days old will be deleted.

Please help me to delete the files which has to check along with data and file name.

Thanks in advance.

-name "hr333m*" -- it will match only the files starts with hr333m

if you have any doubts, then just print the find command output, once you satisified with the output, apply the rm command.

To display the files :

find var/hr/payments/ -name "hr333m*" -mtime +7

To Delete the files : (Once you satisified with the above command)

find var/hr/payments/ -name "hr333m*" -mtime +7 -exec rm -f {} \;