Last Updated: February 25, 2016
· mgile

Ludicrously Fast File Deletion

Scenario: You have a directory with thousands of files totaling more than 20GB in total storage space. Normally, you might try the good ol':

rm -rf full-directory/

Well, that will work...eventually. If you've got a couple hours to spare it will delete your files. However it is extremely inefficient. So what do we do?

rsync to the rescue:

mkdir empty-directory/

rsync -av --delete empty-directory/ full-directory/

The rsync operation will attempt to synchronize the contents of empty-directory with the full-directory, deleting anything that isn't present in empty-directory. The net benefit for us is that it will delete all of our large files in full-directory ridiculously quickly.

Try it out the next time you need to get rid of a ton of old junk bits.