How to delete a large number of files in Linux
How to delete a large number of files
To delete a large number of files in Linux, You need to delete 100,000 files. This is the log written by the previous program, which is growing fast and useless. At this time, the common delete command rm-fr * is not easy to use, because it takes too long to wait. Therefore, we must take some extraordinary measures. We can use the -- delete-before parameter of rsync to quickly delete a large number of files.
1) Create an empty folder:
Mkdir/tmp/test
2) use rsync to delete the target directory:
Rsync -- delete-before-a-H-v -- progress -- stats/tmp/test/log/
In this way, the log directory to be deleted will be cleared and the deletion speed will be very fast. Rsync actually uses the replacement principle, and processing 100,000 files is also deleted in seconds.
Option description:
-- Delete-before: the receiver is deleted before transmission.
-- Progress displays the transmission process during transmission
-- A archive mode: Transfers files recursively and maintains all file attributes.
-- H: Keep a hard-connected File
-- V detailed output mode
-- Stats indicates the transmission status of some files.