/bin/rm: Argument list too long.

After forgetting to add “2>&1″ to the end of my cron job that runs every minute I ended up with a lot of “mail” in my Maildir, about 600,000! So I thought that I could do a simple “rm 11*” (Each file started with a 11)

But I ran into a problem: “Argument list too long.”

So after researching this problem I found out why (It has to do with not being able to fit the supplied argument list and environment into the 128K buffer)

I also found a solution: find . -name ‘11*’ | xargs rm

Three minutes later my Maildir was clear!

Regards,

Steven Roddis

7 Comments so far »

  1. Anonymous said,

    October 9, 2006 @ 4:32 pm

    find . -name ‘11*’ -exec rm “{}” \;

  2. Vinay said,

    November 23, 2006 @ 4:59 pm

    Hi,

    i want to delete all webalizer stats of my server. will this command work for this:

    find . -name ‘/home/*/tmp/webalizer/*’ | xargs rm

    Please let me know.

    Regards,

    Vinay

  3. Steven Roddis said,

    November 24, 2006 @ 1:10 pm

    Yes, but it won’t delete the directories.

  4. Dipu said,

    January 5, 2007 @ 5:50 am

    I feel using exec from find command is bound to fail since the argument list will be too long for it to handle.

    From somewhere else on net.

    getconf ARG_MAX gives the maximum number of arguments that commands can take…

  5. Jeff said,

    January 6, 2007 @ 4:45 am

    Dipu, exec works because find passes the filenames one at a time.

  6. Sadanand said,

    October 14, 2007 @ 8:56 pm

    This helped me a lot. Thanks

  7. Stephen said,

    January 3, 2008 @ 8:05 am

    To touch on the issue Vinay raised, I had to use the -wholename option on the find command to delete files from multiple directories. The following got rid of all the incomplete files in my audio stream directories quite nicely:

    find /usr/local/Streams/ -wholename ‘*/incomplete/*’ -print0 | xargs -0 rm -f

Comment RSS

Leave a Comment

Name:

E-mail:

Website:

Comment:

Recent Comments

  • Josir Gomes: Hi Steve, the meta-package ubuntu-desktop is bloated with huge softwares like OpenOffice, Evolution,...
  • hannah: your that good! ha ha, but seriously.
  • Wiras Adi: Yeah, mathematic operation in text-based CAPTCHA is very easy to break. And I don't think that many sites...
  • Gary: Phew! You saved me lots of hassle :-) The only problem I had was that $_SERVER[’HTTP_AUTHORIZATION ’]...
  • Stephen: To touch on the issue Vinay raised, I had to use the -wholename option on the find command to delete files...

Else wheres