Re: Removing thousands of files using rm

From: Jerry McAllister (jerrymc_at_clunix.cl.msu.edu)
Date: 07/06/04

  • Next message: Bill Moran: "Re: Removing thousands of files using rm"
    To: iaccounts@ibctech.ca (Steve Bertrand)
    Date: Tue, 6 Jul 2004 11:13:19 -0400 (EDT)
    
    

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

    _______________________________________________
    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"


  • Next message: Bill Moran: "Re: Removing thousands of files using rm"