From owner-freebsd-questions@FreeBSD.ORG Tue Jul 6 15:13:40 2004 Return-Path: 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 1D58216A4CE for ; Tue, 6 Jul 2004 15:13:40 +0000 (GMT) Received: from internet.potentialtech.com (h-66-167-251-6.phlapafg.covad.net [66.167.251.6]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7086F43D2D for ; Tue, 6 Jul 2004 15:13:39 +0000 (GMT) (envelope-from wmoran@potentialtech.com) Received: from working.potentialtech.com (pa-plum-cmts1e-68-68-113-64.pittpa.adelphia.net [68.68.113.64]) by internet.potentialtech.com (Postfix) with ESMTP id 9FF8269A40; Tue, 6 Jul 2004 11:13:38 -0400 (EDT) Date: Tue, 6 Jul 2004 11:13:37 -0400 From: Bill Moran To: "Steve Bertrand" Message-Id: <20040706111337.087ae8cb.wmoran@potentialtech.com> In-Reply-To: <3703.209.167.16.15.1089123354.squirrel@209.167.16.15> References: <3703.209.167.16.15.1089123354.squirrel@209.167.16.15> Organization: Potential Technologies X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i386-portbld-freebsd4.9) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org Subject: Re: Removing thousands of files using rm X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jul 2004 15:13:40 -0000 "Steve Bertrand" wrote: > I often have the need to remove hundreds or even thousands of files from a > single directory (very often). Using rm, I usually get: > > pearl# rm -rvf * > /bin/rm: Argument list too long. > > Is there any way to work around this instead of having to select a small > bunch of files at a time to remove? > > The directory I am trying to remove the files from is always hot, so > deleting the directory is unfortunately not an option. (I don't think). I think the canonical answer is to use find with the -delete option. Like this: find /dir -delete The longer answer is that the reason it fails is because the shell expands the * into a list of all filenames before it actually runs rm. This list is too long for the command line, thus causing the error. Knowing this, any method of deleting the files that doesn't require the shell to expand the list will work as well. There are also tricks you can use to configure the shell to use a longer command line, but I don't remember details. Search the list archives. I asked this same question a year or so back, and the thread that resulted is very informative. -- Bill Moran Potential Technologies http://www.potentialtech.com