Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Jul 2004 11:13:37 -0400
From:      Bill Moran <wmoran@potentialtech.com>
To:        "Steve Bertrand" <iaccounts@ibctech.ca>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Removing thousands of files using rm
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>

next in thread | previous in thread | raw e-mail | index | archive | help
"Steve Bertrand" <iaccounts@ibctech.ca> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040706111337.087ae8cb.wmoran>