06 January 2010

rm - too many arguments

I was trying to delete about 55,000 files in an Ubuntu directory the other day. Something along the lines of:

rm -f *


This failed with a "too many arguments" error. The root-cause of this seems to be a little involved, but the simple one-line workaround is:

find ./ -name '*' -print0 | xargs -0 rm

2 comments:

Anonymous said...

why not

find . -name "*" -exec rm -f {} \;

Richard G. said...

Not sure if that would also work or not. The solution I posted is one I found which accounted for spaces in the file names and I used this successfully.

I'm not a Linux guru. There may be many ways to do it. I'll leave it for others to provide more detailed and informative comments.

Post a Comment