[mdlug] Script to delete old files?

Carl T. Miller carl at carltm.com
Tue Mar 1 08:52:20 EST 2011


Stan Green wrote:
> My thought is a script something like this (pseudo code):
> df > FreeSpace
> if FreeSpace is less then 25%
> if FreeSpace is less then 50% do
> 	delete the oldest file
> 	df > FreeSpace
> Loop until FreeSpace is greater then 50%

This would work, although if you have a lot of files it
might run for a long time.  A way to speed it up would
be to delete files older than X weeks/days/hours/minutes.
If this runs every week, you could have it count down
from 8 weeks to 1 week.  The find command could be used
to find and delete the files relatively quickly.

c





More information about the mdlug mailing list