Deleting lots of files at once

I recently have had to get rid of cache files numbering hundreds of thousands (how I got there is a story for another day).

The most obvious solution would be to run

rm *

This command basically says delete everything in the current folder.

The only problem is that you are very likely to run into “Too many arguments” error. This is because the listing operation is first carried out then passed to the rm function.

A better way to do it

ls | xargs rm

This lists the files and then passes them on to the xargs function which then feeds the results one by one to the rm function.

The xargs really is a powerful tool. To explore it out some more check