Removing thousands of files using rm

Steve Bertrand iaccounts at ibctech.ca
Tue Jul 6 07:39:45 PDT 2004


>> 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.
>




More information about the freebsd-questions mailing list