Page 1 of 1
How to delete millions of files in a directory quickly?
Posted: Tue Nov 26, 2013 10:04 pm
by harryrundles
Hello,
Does anyone have a recommendation on how to delete millions of files in a directory and in sub folders under that directory?
I tried using the rm -rf command but it takes FOREVER!!!
Re: How to delete millions of files in a directory quickly?
Posted: Wed Nov 27, 2013 3:07 am
by JimKnicely
Hi Harry,
I use the rsync trick ...
1. Create an empty directory
2. Use the rsync command in conjunction with the --delete option to synchronize the empty directory with the directory you want to empty ...
Example:
Code: Select all
[dbadmin@vertica02 vertica_backups]$ pwd
/home/dbadmin/vertica_backups
[dbadmin@vertica02 vertica_backups]$ mkdir blank
[dbadmin@vertica02 vertica_backups]$ ls -lrt blank
total 0
[dbadmin@vertica02 vertica_backups]$ rsync -a --delete /home/dbadmin/vertica_backups/blank/ /home/dbadmin/vertica_backups/v_snowfall_node0001/
I learned this neat trick from here:
http://www.slashroot.in/which-is-the-fa ... s-in-linux