delete files with a date in their name - based on current date

I currently have a cron job setup to move log files to an archive directory every night.  The name of the new file is "<filename>.<date>".  I now want to setup a job that will delete the archive files based on the date appended to the file name.  I need to use the current system date and delete any files older than seven days.

How can I do this?  Thanks - Lisa

** SAMPLE LOG FILE NAMES **
error_log.040502
access_log.040502
error_log.040402
access_log.040402
error_log.040302
lphillips120898Asked:
Who is Participating?
 
ilikenineConnect With a Mentor Commented:
go the directory where you have the log files
and run this command
rm -f `find . -type f -mtime +7 `

enjoy
GG
0
 
LeeMillerCommented:
I have a script that will leave xnumber of new files and delete any beyond that number. Its not exactly what your asking for, but if you have an idea of how many files are created in 7 days, it will delete any above that number.  I will post it if it will help.
0
 
ilikenineCommented:
well i assumed that the date appended at the end of file name is same as the last modified date.
Hope this is a valid assumtion.

Thanks
GG
0
 
lphillips120898Author Commented:
the command worked like a champ - can you tell me exactally what it does?  What is mtime?

Thanks,

Lisa
0
 
ilikenineCommented:
find . -type f -mtime +7

type man find and you will know.

Still, it will find all the files(-type f) in the present directory with has modified date of seven days or earlier
(-mtime +7)

-gg
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.