Sunday, September 30, 2007

Deleting a Lot of files

Removing a large number of files

It so happened that I had to remove a really large number of files from a directory (a botched un-rar operation created a bunch of bogus files). Running rm from commandline with a wildcard, however, produced the following output:

 /bin/rm: Argument list too long.

Running

 find . -name 'blah*' -exec rm -rf {} \;

produced a similar error for find. The solution (courtesy of this page) lies in the wonders of pipes. This command:

 find . -name 'blah*' -print0 | xargs -0 rm -rf

did the trick without complaining (because it sends the results of find to rm one by one, rather than in one large batch).

No comments: