Delete large number of files

I had to delete thousands of files. The command “rm” simply took forever. Then I learned you can use rsync to do the job.

First, create an empty directory such as

mkdir empty

Then, rsync it with the folder you want to delete using

rsync -av --delete empty/    todelete/

This is super fast comparing to rm.

Using perl

perl -e 'for(<*>){((stat)[9]<(unlink))}'