Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Jul 2004 11:13:19 -0400 (EDT)
From:      Jerry McAllister <jerrymc@clunix.cl.msu.edu>
To:        iaccounts@ibctech.ca (Steve Bertrand)
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Removing thousands of files using rm
Message-ID:  <200407061513.i66FDLa16321@clunix.cl.msu.edu>
In-Reply-To: <3849.209.167.16.15.1089124792.squirrel@209.167.16.15> from "Steve Bertrand" at Jul 06, 2004 10:39:52 AM

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
> 

The find method is right for doing this now and then.
But if you are doing this frequently and there is a reasonable pattern
to the file names you are crating and then deleting, you might want to
create a special directory for them and then when it is time to delete
them, just do an  rm -rf on the directory - as in:
    mkdir junkdir
      fill it up with those files and do whatever you need.
    rm -rf junkdir
t might take some thought to categorize the files so the right ones
are stashed in the directory.

////jerry

> 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.
> >
> 
> 
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
> 



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