Delete a large number of small files in Linux

Source: Internet
Author: User

In Linux, when "rm-rf *" is used to delete a large number of small files in Linux, an error similar to the following may be reported:/bin/rm: argument list too long. this is because the wildcard "*" will be replaced by each matching file name during execution, for example, "rm-rf file1 file2 file3 file4 ″. The system only allocates a small buffer to sort the list. If the buffer is full, shell cannot execute this command. To solve this problem, many people use the find command. Find is used to search for each file, and then pass the rm command one by one based on the file name. The format is as follows: find. -type f-exec rm-v {}\; but this method is very slow for a large number of files. For example, I have deleted more than 200 small files in a directory. The method is to use the built-in "-delete" parameter of the find command. Using this method to delete files, the speed is about 2000 files/second, which is greatly improved compared with the previous method. You can also add the "-print" parameter to display each deleted file. Find. -type f-deletefind. -type d-print-delete, but I do not recommend adding this parameter. If you want to observe the speed of file deletion, we recommend that you use the df-I command to view the indoe node changes.

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.