Removing thousands of files using rm

Lowell Gilbert freebsd-questions-local at be-well.ilk.org
Tue Jul 6 07:26:08 PDT 2004


"Steve Bertrand" <iaccounts at ibctech.ca> writes:

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

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

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