Faster Folder/Files Deletion Command in Linux for Thousands of Files/SubFolders


I have a cached folder for one of my websites that stores quite a lot of sub folders and thousands of static HTML files. Some times, if I change some core PHP code, I then need to purge these HTML files so next time when the page is visited a updated cached HTML will be generated.  I found out it takes ages (some times more than an hour) to delete the entire cache folder using:

rm -rf cached/

This is really inconvenient. Another much faster alternative is to use the rsync command to delete the folder using the following command.

mkdir empty_dir
rsync -a --delete empty_dir/ folder2delete/

The rsync is a file transfer program capable of efficient remote update via a fast differencing algorithm. You can type in rsync –help or man rsync to see the usages (different parameters/options)

We need to create a empty directory (or use an existing one) before using this command. Then the above command will synchronize the content of the empty directory into (overwrite) the targeted folder, so at the end, all the folders/sub folders/files will be deleted.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
246 words
Last Post: Unrolling Loop in C/C++/Java Style
Next Post: Learning Processing - Random Pixels

The Permanent URL is: Faster Folder/Files Deletion Command in Linux for Thousands of Files/SubFolders

Leave a Reply