Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Jul 2004 10:39:52 -0400 (EDT)
From:      "Steve Bertrand" <iaccounts@ibctech.ca>
To:        "Lowell Gilbert" <freebsd-questions-local@be-well.ilk.org>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Removing thousands of files using rm
Message-ID:  <3849.209.167.16.15.1089124792.squirrel@209.167.16.15>
In-Reply-To: <44pt79mcu9.fsf@be-well.ilk.org>
References:  <3703.209.167.16.15.1089123354.squirrel@209.167.16.15> <44pt79mcu9.fsf@be-well.ilk.org>

next in thread | previous in thread | raw e-mail | index | archive | help

>> 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?
>
> Not exactly, but find(1) will do the job for you.
> Typically you would use it with xargs(1).

Thanks to all who replied. This following suggestion worked very, very
well, and extremely quickly:

> find /path-to-directory -type f -print | xargs rm

I'll read up on find and xargs as this approach appears to be easily
scripted and cronned.

Tks again!

STeve


>
> You may need to add some options to those commands depending on your
> situation.  For example, if you have embedded whitespace characters in
> the file names or if you don't want to descend into subdirectories.
>




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