Solved

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

Posted on 2002-04-05
5
255 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:lphillips120898
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Expert Comment

by:LeeMiller
ID: 6921095
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
 
LVL 1

Accepted Solution

by:
ilikenine earned 150 total points
ID: 6921181
go the directory where you have the log files
and run this command
rm -f `find . -type f -mtime +7 `

enjoy
GG
0
 
LVL 1

Expert Comment

by:ilikenine
ID: 6921194
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
 

Author Comment

by:lphillips120898
ID: 6921547
the command worked like a champ - can you tell me exactally what it does?  What is mtime?

Thanks,

Lisa
0
 
LVL 1

Expert Comment

by:ilikenine
ID: 6925955
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question