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

Comments

  1. why not

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

    ReplyDelete
    Replies
    1. This would start one rm process for every file. 55,000 processes might cause a slight performance problem.

      Delete
  2. 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.

    ReplyDelete

Post a Comment

Popular posts from this blog

Wkhtmltopdf font and sizing issues

Import Google Contacts to Nokia PC Suite

Can't delete last blank page from Word