Deleting hundreds of thousands of files on Linux

A badly configured server which leaves hundreds of thousands of temporary files in a single folder is a bummer. Not being able to delete them easily is even more so. I tried the standard rm -rf ./*, but all I got was the following error message:

/bin/rm: Argument list too long

I tried to devise more clever patterns to delete them in chunks but it was just horribly slow anyway. This blog post from Hosting Blog came to the rescue with the following terminal command:

find . -name 'pattern*' | xargs rm

Poof! Four hundred thousand files disappeared in a few seconds. Awesome stuff!

Share Button
Posted in Blog Tagged with: , , , ,

Leave a Reply