rm complains argument list too long

October 20th, 2007 mysurface Posted in Common, find, rm, xargs | Hits: 48720 | 5 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 

5 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

Leave a Reply