deleting automatically the oldest file from a harddisk

Ian Smith smithi at nimnet.asn.au
Tue Nov 14 13:54:09 UTC 2006


On Mon, 13 Nov 2006 Koen de Wijs wrote:

 > I have a ftp -server. I use a harddisk of  9 Gb for the ftp-directory.
 > 
 > This isn't very big so I want to throw away the oldest file if the disc 
 > is full.

I'd tend to define 'full' as perhaps 8GB in that situation, and likely
protect at least some ftp directories from purely date-based purging.

 > I can write a cronjob that checks every minute. But isn't there another 
 > solution;

If you leave enough headroom then hourly might be often enough?

 > Can't I just write a C program that listens to some systemcalls and 
 > automatically deletes the oldest file if the harddisk is full???

Well you can do anything in C if you know how and have the time :) but a
small script using existing utilities would be a lot easier.

Sounds like a job for find(1) to me.  Search for the numerous primaries
matching 'time' or 'newer', also see -size and maybe others useful for
generating a list of pathnames of your candidate(s) to feed to rm(1)

Cheers, Ian



More information about the freebsd-questions mailing list