'Absolute fastest way to recursively delete all files and folders in a given path. Linux

I am looking for the absolute fastest method of performing unlink and rmdir commands on a path containing millions of files and thousands of folders.

I have found following perl one-liner, but this does not recurse and also performs a stat before each unlink (this is unnecessary):

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


Solution 1:[1]

It's not going to make much difference either way - CPUs are fast, disks are slow. Most of the work - however you do it - will be the traverse and unlink system calls.

There's not really a way to speed that up (well, short of maybe just initialising/quickformatting your disk and starting over).

Solution 2:[2]

The fastest way to delete all files and folders recursively that I was able to find is:

perl -le 'use File::Find; find(sub{unlink if -f}, ".")' && rm -rf *

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sobrique
Solution 2 DreamFlasher