Rsync is a sync tool I just used it to do data synchronization operation did not want to do file deletion operation, but today saw an article can implement file deletion operation, below we take a look.
Use rsync to synchronize an empty directory. For the million-level file directory is the basic second Delete, enter the OK.
The steps are as follows:
1. Create an empty directory
Mkdir-p/tmp/rsync_blank
2, the establishment needs to clear the target directory
/data/ooxx
3, use rsync Sync Delete (Note the "/" Behind the directory), the overall efficiency will be a number of orders of magnitude.
Rsync–delete-before-a-h-v–progress–stats/tmp/rsync_blank//data/ooxx/
Option Description:
–delete-before recipient to delete before transmission
–progress Displays the transfer process during transmission
-a archive mode, which represents the transfer of files recursively and maintains all file attributes
-H Keep Hard connected files
-V Verbose output mode
-stats gives the transfer status of some files
Generally we do not need to show progress, use the following command to
Rsync–delete-before-a-h/tmp/rsync_blank//data/ooxx/
So the cache directory we want to delete will be emptied.
Tips
Error occurs 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 both SRC and Dest properties are directory "D", the meaning is to delete all files in the directory to make it empty
The most important thing is that it's handled fairly quickly, dealing with several G files, which is the second level.
The core content is that rsync actually uses the principle of substitution.