Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete everyfile on a certain date?

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a script that is running everyday. I want to add a line or several lines and deletes every file in the directory only on a particular date, lets say three months from now. Meaning the delete portion will not run until the date matches what I want it to.

Thanks for the help!
.//beaster
 
If you mean that you want to delete any files that are more than 3 months old (or 90 days, say), then use find ...
Code:
cd dir
find . -type f - mtime +90 | xargs rm -f

NB: This will delete files, so take care! One by one, the penguins steal my sanity. X-)

 
You could set up a cron job as well
crontab has 5 time fields followed by an executable job field. Fields are: minute 0-59, hour 0-23, day of month 1-31 month 1-12 and day of week 0-6 where 0=Sunday. So at 1.30am 10th May on Sunday run your delete script

Crontab entry
30 1 10 5 0 /your_script/to/deletefiles or the find command

However this will only run once, until you ammend crontab: - "crontab -e"

It appears you want to make the change now and forget about it, so I think your best bet is as ajayacee says is to use the find and remove command, then put it into
crontab.


 
Yea I just remembered that. I think cron is the best way to do it.....thanks for jarring my memory.

.//beaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top