Re: Removing thousands of files using rm

From: Bill Moran (wmoran_at_potentialtech.com)
Date: 07/06/04

  • Next message: Hugo Silva: "Re: sound-card // dsp1"
    Date: Tue, 6 Jul 2004 11:13:37 -0400
    To: "Steve Bertrand" <iaccounts@ibctech.ca>
    
    

    "Steve Bertrand" <iaccounts@ibctech.ca> wrote:

    > 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?
    >
    > The directory I am trying to remove the files from is always hot, so
    > deleting the directory is unfortunately not an option. (I don't think).

    I think the canonical answer is to use find with the -delete option. Like
    this:

    find /dir -delete

    The longer answer is that the reason it fails is because the shell expands
    the * into a list of all filenames before it actually runs rm. This list
    is too long for the command line, thus causing the error. Knowing this,
    any method of deleting the files that doesn't require the shell to expand
    the list will work as well. There are also tricks you can use to configure
    the shell to use a longer command line, but I don't remember details.

    Search the list archives. I asked this same question a year or so back, and
    the thread that resulted is very informative.

    -- 
    Bill Moran
    Potential Technologies
    http://www.potentialtech.com
    _______________________________________________
    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: Hugo Silva: "Re: sound-card // dsp1"

    Relevant Pages