Script for deleting files based on date
Does any one know of any ready written scripts that I can base a script of my own, which will be responsable for deleting files based on date. If that file is over 1 month old, it gets deleted. This will be run from a cron tab.
I have never even attempted to write a script before, and have no idea where to start, so any pointers would be appreciated!!! |
The Linux Cookbook has some tips on things like this; check out this chapter for specifics.
|
how 'bout:
assume current dir has the old files find . -mtime +30 -exec rm {} \; and cron that to run each night. Should delete for each file not modified for a month Code:
futur6/usr/users/wayne/junk> ls -lart |
Here's mine. If you want to change the age before deleting, change the part -mtime +90 to -mtime +30
#!/bin/bash filename=`date '+%m%d%y'` tar -cvzf /mnt/backup/${filename}.tar.gz /home #Delete old files with the following command find /mnt/backup -type f -name '*.gz' -mtime +90 -exec rm {} \; |
All times are GMT -5. The time now is 02:38 AM. |