> ## Content Index
> Fetch the complete content index at: https://www.binarysludge.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Delete Millions of Files (Linux)
- URL: https://www.binarysludge.com/2012/01/01/how-to-delete-millions-of-files-linux/
- Published: 2012-01-01T12:00:05.000Z
- Updated: 2015-01-16T12:31:41.000Z
- Author: Andrew Martin
- Tags: file descriptors, file system, linux, Perl, system adminstration, #Import 2026-10-22 12:56

![Top Marks](http://c213.r13.cf3.rackcdn.com/broken hard disk.jpg "Smashed Hard Drive") 

Deleting millions of files from a directory can be a daunting task. `rm -rf ` *will expand the ``* to glob every file in the directory and return an error such as "Argument list too long". `find . -type f -delete` will try to get a list of all files before deleting them, and is very slow.

The answer is to bypass BASH completely:

perl -e 'chdir "BADnew" or die; opendir D, "."; while ($n = readdir D) { unlink $n }'

Thanks to [Randal L. Schwartz](http://blogs.perl.org/users/randal%5Fl%5Fschwartz/2011/03/perl-to-the-rescue-case-study-of-deleting-a-large-directory.html?ref=binarysludge.com)