Last Updated: February 25, 2016
·
423
· thegreendruid

Bulk remove a large amount of files from a directory

Most people know the command

rm dir/*

It can be dangerous but if you know what is in the target directory and you want to remove all the files, its fine. A problem will creep up however if you have a lot of files in a directory (I'm talking hundreds of thousands, if not millions).

You tend to get this error:

unable to execute /bin/rm: Argument list too long

So a nice workaround is to use the find program with the delete flag

find . -name "dir/*" -delete

This technique works very quickly and generally a better way of working with files in a directory