Quickly delete a large number of files under linux

  
 

The method of quickly deleting a large number of files under linux, using rsync delete, the speed is much faster than commands such as rm or find.

For such a story, there is no such thing as a clear story about the test environment. Brother has always been skeptical. First Baidu, there are only conclusions, no test data. Google has test data, but the test environment is not written. Personal feelings have a lot to do with the file system format.

After taking the time to test it today: the test machine configuration is lower, it is a desktop computer bought N years ago. Sata hard drive Intel (R) Pentium (R) D CPU 3.20GHz4G memory. EXT4 file system: /dev/mapper/VolGroup-lv_home on /home type ext4 (rw, noatime)Linux www 2.6.32-220.7.1.el6.i686 #1 SMP Tue Mar 6 21:21:22 GMT 2012 i686 i686 I386 GNU/LinuxCentOS release 6.2 (Final)rsync version 3.0.6 protocol version 30

Create a 16/256/directory structure with 250 files in the deepest directory, 300 bytes each. Mkdir.php

/**16 * 256 * 250*/for($i=0; $i<=0xF; $i++) {for($j=0; $j<=0xF; $ j++) {for($m=0; $m<=0xF; $m++) {$dirname = sprintf("test/%x/%x%x", $i, $j, $m);//Create directory mkdir($dirname, 0755, TRUE); for($k=-0; $k<250; $k++) {$filename = sprintf("%s/%d.html", $dirname, $k ); file_put_contents($filename, str_repeat("111", 100) );}}}}

Find It takes 35 seconds to traverse: [modify@www test]$time find ./-type f

Copyright © Windows knowledge All Rights Reserved