-bash: /bin/rm: Argument list too long

I accidentally created more than 50K empty files in a folder. When I tried to remove them using rm -rf *.tmp, I got the error -bash: /bin/rm: Argument list too long.

It turns out bash tries to expand the * into a full list, but that list became too long.

Here is how to delete that many files:

find . -name '*.tmp' | xargs rm

Ref:
https://yooplug.com/portal/plugin/support_manager/knowledgebase/view/45/deleting-tons-of-files-in-linux-argument-list-too/
https://www.tidyhosts.com/blog/resolve-binrm-argument-list-long-error/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s