From owner-freebsd-stable@FreeBSD.ORG Thu Jan 20 14:46:13 2005 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1014E16A4CE for ; Thu, 20 Jan 2005 14:46:13 +0000 (GMT) Received: from sferics.mongueurs.net (sferics.mongueurs.net [81.80.147.197]) by mx1.FreeBSD.org (Postfix) with ESMTP id 22A0F43D2F for ; Thu, 20 Jan 2005 14:46:12 +0000 (GMT) (envelope-from david@landgren.net) Received: from [127.0.0.1] (exo.bpinet.com [81.80.147.206]) by sferics.mongueurs.net (Postfix) with ESMTP id 4E24CAA47 for ; Thu, 20 Jan 2005 15:46:10 +0100 (CET) Message-ID: <41EFC430.9010308@landgren.net> Date: Thu, 20 Jan 2005 15:46:08 +0100 From: David Landgren Organization: The Lusty Decadent Delights of Imperial Pompeii User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: stable@freebsd.org References: <00b001c4fea0$7533d490$6745a8c0@MESE> <20050120094551.GK79646@cirb503493.alcatel.com.au> In-Reply-To: <20050120094551.GK79646@cirb503493.alcatel.com.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: Very large directory X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Jan 2005 14:46:13 -0000 Peter Jeremy wrote: > On Wed, 2005-Jan-19 21:30:53 -0600, Phillip Salzman wrote: > >>They've been running for a little while now - and recently we've noticed a >>lot of disk space disappearing. Shortly after that, a simple du into our >>/var/spool returned a not so nice error: >> >> du: fts_read: Cannot allocate memory >> >>No matter what command I run on that directory, I just don't seem to have >>enough available resources to show the files let alone delete them (echo *, >>ls, find, rm -rf, etc.) > > > I suspect you will need to write something that uses dirent(3) to scan > the offending directory and delete (or whatever) the files one by one. > > Skeleton code (in perl) would look like: > > chdir $some_dir or die "Can't cd $some_dir: $!"; > opendir(DIR, ".") or die "Can't opendir: $!"; > while (my $file = readdir(DIR)) { > next if ($file eq '.' || $file eq '..'); > next if (&this_file_is_still_needed($file)); > unlink $file or warn "Unable to delete $file: $!"; > } > closedir DIR; similarly, opendir(DIR, $some_dir ) or die "Can't open dir $some_dir: $!"; while ( defined(my $file = readdir(DIR))) { print "$file\n" unless ($file eq '.' || $file eq '..'); } closedir(DIR); ...will print the files one per line, which can be piped to more or redirected to another file. This will let you get a feel for the names of the files in the directory. It could then be cleaned up with various pipelines like egrep 'foo|bar|rat' | xargs rm Note: you want to wrap the my $file = readdir(DIR) in a defined(), otherwise your loop will exit early if you come across a file named 0 (zero). David