简体   繁体   中英

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))}'

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).

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 *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM