rm -rf ‘Argument list too long’, delete a directory containing millions of files, the most effective way

Option 1:

Create an empty directory and rsync to the directory which you want to delete

# mkdir empty_dir
# rsync -a –delete empty_dir/     delete_directory/

# rm -rf  delete_directory

 

Option 2:

# cd your_delete_directory
# perl -e ‘for(<*>){((stat)[9]<(unlink))}’

# rm -rf  your_delete_directory