Skip site navigation (1)Skip section navigation (2)
Date:      06 Jul 2004 10:26:06 -0400
From:      Lowell Gilbert <freebsd-questions-local@be-well.ilk.org>
To:        "Steve Bertrand" <iaccounts@ibctech.ca>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Removing thousands of files using rm
Message-ID:  <44pt79mcu9.fsf@be-well.ilk.org>
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> 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.



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