Delete a large number of files in Linux

Source: Internet
Author: User

Mainly refer to the http://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux

Create 0.5 million files first

➜  test    i  $(  );  text >>$i.txt;                 
1. rm
➜  test    -f * /home/hungerr/test [yn]?:  -f *  .63s user .29s system % cpu  total

Rm does not work because there are too many files.

2. find
➜  test    ./ -type f -exec  ./ -type f -exec  {} \;  .86s user .13s system % cpu : total

About 43 minutes, my computer ...... While watching the video, you can delete it.

3. find with delete
➜  test    ./ -type f - ./ -type f -delete  .43s user .21s system % cpu : total

It takes 9 minutes.

4. rsync

First, create an empty folder named "blanktest ".

➜  ~   rsync -a --delete blanktest/ test/-a --delete blanktest/ test/  .59s user .86s system % cpu  total

16 s, very good and powerful.

5. Python
import osimport timestime=time.time()for pathname,dirnames,filenames in os.walk('/home/username/test'):    for filename in filenames:        file=os.path.join(pathname,filename)        os.remove(file)ftime=time.time()print ftime-stime      
➜  ~

It takes about 8 minutes.

6. Perl
➜  test    -e  -e   .28s user .23s system % cpu  total

16 s, this should be the fastest.

 

Statistics:

Command Time-consuming
Rm Too many files, not available
Find with-exec 0.5 million it takes 43 minutes for a file
Find with-delete 9 minutes
Perl 16 s
Python 8 minutes
Rsync with-delete 16 s

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.