Get past "argument list too long" using xargs

Submitted by jeff on Tue, 05/27/2008 - 17:22.

Recently I kept geting “Argument list too long” error while trying to delete about 12,000 files from a directory. It was simply too much for rm * to handle.

[mycomputer:~ bob$ rm *
bash: /bin/mv: Argument list too long

To get around this you do this:

ls | xargs rm

That will pipe the ls output as an argument to rm until everything is gone. Very excellent. This will work with other shell commands as well.