From owner-freebsd-questions@FreeBSD.ORG Tue Nov 14 13:54:09 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6637C16A49E for ; Tue, 14 Nov 2006 13:54:09 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from gaia.nimnet.asn.au (nimbin.lnk.telstra.net [139.130.45.143]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4D9A243D66 for ; Tue, 14 Nov 2006 13:54:01 +0000 (GMT) (envelope-from smithi@nimnet.asn.au) Received: from localhost (smithi@localhost) by gaia.nimnet.asn.au (8.8.8/8.8.8R1.4) with SMTP id AAA24018; Wed, 15 Nov 2006 00:53:52 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Wed, 15 Nov 2006 00:53:51 +1100 (EST) From: Ian Smith To: Koen de Wijs In-Reply-To: <20061113200345.B476516A4F5@hub.freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: freebsd-questions@freebsd.org Subject: deleting automatically the oldest file from a harddisk X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Nov 2006 13:54:09 -0000 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