rm complains argument list too long

October 20th, 2007 mysurface Posted in Common, find, rm, xargs | Hits: 70280 | 6 Comments »

There is a limitation of rm command, where you can’t delete a large groups of files with *. For examples,

rm -rf something*

If there are large amount of files initiate with something, rm will fails and complains

/bin/rm: Argument list too long.

The solution is to make use of find, xargs and rm.

find . -name 'something*' -print0 | xargs -0 rm -rf 

6 Responses to “rm complains argument list too long”

  1. This works too. “ls | xargs rm”

  2. Hi,

    What I love Linux for is that one task can be done in several ways. So, to do what you need with rm, you can execute:

    ls | while read file;do rm -rf $file;done

    Not so short as previous one, but this one is more flexible… :)

  3. There’s an even shorter way if you have GNU find:

    find . -name ‘something*’ -delete

    I’m not sure find programs have the -delete action, but GNU find does.

  4. danesh: That is much much shorter.
    Artem : I totally agree with you.
    Jim : Will try that when I have another brunch of rubbish to remove.

  5. possibly faster than xargs and/or find

    printf “rm %s\n” something*|sh

  6. I tend not to create many remarks, however i did a few searching and wound
    up here rm complains argument list too long ? Linux by Examples.
    And I do have 2 questions for you if you do not mind. Could
    it be only me or does it give the impression like some of these
    comments look like they are written by brain dead folks?
    :-P And, if you are writing at other places, I would
    like to keep up with anything new you have to post. Could you
    list of the complete urls of all your shared sites like your linkedin profile, Facebook page or twitter

Leave a Reply