Linux quickly deletes a large number of small file methods

Source: Internet
Author: User
Tags rsync

You can do the following two steps:

1. First step: Create an empty folder: Mkdir/tmp/blank

2, the second step: Execute the following command: rsync--delete-before-d/tmp/blank//home/stormnode/store/html/new/

Linux quickly deletes a large number of small file methods

Using RM-RF * When we want to delete tens of thousands of or hundreds of thousands of or even millions of of files in a Linux system is not very useful because we have to wait a long time. In this case we can use the Linux system command rsync to skillfully handle.    Rsync actually uses the replacement principle, processing hundreds of thousands of files is also the second delete. 1. rsync installation, some systems have the command installed by default
Ubuntu System: sudo apt-get install Rsyncfedora system: sudo yum install rsync other can source installation, download to the following website
http://rsync.samba.org

2. Rsync provides some parameters related to deletion

Rsync--help | grep delete     --del                         and nbsp      an alias for--delete-during     --delete             &NB Sp            delete extraneous files from destination dirs     --delete-before             receiver deletes before transfer, not during     --delete-during             receiver deletes during transfer (default)      --delete-delay &NB Sp             find deletions during, delete after     --delete-after   &NB Sp            receiver deletes after transfer, not during     --delete-excluded        also delete excluded files from destination dirs     --ignore-errors &nbsp           Delete Even if there are I/O errors     --max-delete=num    do N ' t delete more than NUM files where--delete-before recipients are deleted before transfer  

3. Example

empty the directory or file as follows:
1. Create an empty directory first
Mkdir/data/blank
2. Delete the target directory with rsync
rsync--delete-before-d-a-h-v--progress--stats/data/blank//var/edatacache/or rsync--delete-before-d/data/ blank//var/edatacache/

This allows the/var/edatacache directory to be emptied quickly. Option Description:
–delete-before the recipient to delete before transferring
–progress display the transfer process during transmission
-a archive mode that represents recursively transferring files and keeping all file attributes
-H Keep hard-connected files
-V Verbose output mode
–stats gives the transmission status of some files-D transfer directories without recursing
3, can also be used to delete large files
If we have a dozens of g or even hundreds of files under/root/, now we're going to delete it
.
Create an empty file
touch/root/empty
Second, use rsync to empty the/root/data file
rsync--delete-before-d--progess--stats/root/empty/root/data
Note:
error when SRC and dest files are inconsistent in nature
when both SRC and Dest properties are file "F", it means emptying the contents of the file rather than deleting the file
when the SRC and Dest properties are both directory "D", it means deleting all files in that directory and making them empty directories

Linux quickly deletes a large number of small file methods

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.