1

This blog gives different ways of deleting Big Directories and their relative times for deleting a directory with 500,000 files. The script using perl is reported to be fastest, which is given by

cd yourdirectory
perl -e 'for(<*>){((stat)[9]<(unlink))}'

This answer is also reported in StackExchange-Unix&Linux here. The current script can only delete files just one level under the directory. Can anyone provide an equivalent perl script that deletes all subdirectories and their contents recursively?

  • What's wrong with using rm -Rf? – Jan Oct 6 '15 at 19:07
  • agreed with Jan - the blog article referenced in the question seemed to give up too easily when "rm -f *" failed. cd .. and rm -rf the directory. – Jeff Schaller Oct 6 '15 at 19:40
  • What is that stat call doing, and why is it in a boolean context with the unlink ?? (A more legible Perl answer would quite possibly involve File::Path qw/remove_tree/.) – thrig Oct 6 '15 at 19:47
  • 1
    @thrig: Read this for more details. – cuonglm Oct 7 '15 at 1:33
  • 1
    @JeffSchaller: rm -rf can fail with error argument list too long for huge files. – cuonglm Oct 7 '15 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.