Removing thousands of files using rm

Richard P. Williamson richard.williamson at u4eatech.com
Tue Jul 6 07:28:23 PDT 2004


At 15:15 06/07/2004. Steve Bertrand had this to say:
>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?

find /path/to/dir -exec rm -rvf {} \;

use /path/to/dir instead of cd /path/to/dir; find . ... because
it is very easy to forget the cd /path/to/dir step.  Doing
find . -exec rm -rvf {} \; in, for example, / is Not Recommended(tm)
Also, there is a space between the {} and the \;, don't skip it,
as cryptic error messages result.

man find for more info on what you can do with find.

HTH,
rip



More information about the freebsd-questions mailing list