Solved

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

Posted on 2002-04-05
5
251 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nodeip 9 75
auto mounter on solaris 1 52
Sed question 2 68
Unix Script: Loop over all days of a month 17 88
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now