Yesterday encountered the need to delete a large amount of files under Linux, you need to delete hundreds of thousands of files. This is a log of the previous program, growing fast and useless. This time, we often use the delete command RM-FR * is not useful, because the time to wait too long. So we have to take some very good measures. We can use rsync to quickly delete large numbers of files.
1. Install rsync First:
yum install rsync
2. Create an empty folder:
mkdir /tmp/test
3. Delete the target directory with rsync:
rsync --delete-before -a -H -v --progress --stats /tmp/test/ log/
The log directory that we want to delete will be emptied and deleted very quickly. Rsync actually uses the replacement principle, processing hundreds of thousands of files is also the second delete.
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 transfer status of some files
(summary) The fastest way to delete massive files using rsync under Linux