If you don't want to wait, and you want to avoid downtime, or you just need to get rid of the folder fast, queue the delete operation via mv
on your next reboot. Also, the mv
file operation is always faster than anything else, and no need to wait for blocking file-io operation, and continue what you are currently doing on that folder.
Just mv folder_to_be_deleted /tmp/folder_queue_for_deletion
. Files in the /tmp directory will be deleted upon your next reboot.
Benchmark:
$ cat make_million_files.sh
#!/usr/bin/env bash
mkdir folder_to_be_deleted
for i in $(seq 0 1000000); do
touch folder_to_be_deleted/$i;
done
$ ./make_million_files.sh
real 66m3.613s
user 5m47.507s
sys 61m15.432s
IO blocking operation
$ rm -rf folder_to_be_deleted
real 0m32.451s
user 0m2.086s
sys 0m25.094s
Non-IO blocking operation (Queue deletion on next reboot)
$ mv folder_to_be_deleted /tmp/folder_queue_for_deletion
real 0m0.012s
user 0m0.001s
sys 0m0.010s
In essence, the benefit is noticeable if you have multiple folders with lots of subfolders and you want to delete them fast, without downtime in your work, you might consider this solution, as it only takes 60 seconds to delete a million folders with lots of subfolders.
For 1000 folders with lots of subfolders, it would take ~1 hour of blocking IO using rm -rf
, vs. 12 seconds via mv
. And it would just take 60 seconds of boot time to delete everything. Finally, if you don't want to reboot, just mv
the folder out of your way, and rm -rf
it somewhere (other TTY session, etc.).