How to Delete a Folder With a Lot of Files in Linux i.e Argument List Too Long Error

If you have ever had to delete a lot of files within a folder and files on every variant of Linux using the remove command, you might have seen the error below. In this article, we are going to try other approaches to fix this error and you safely and quickly delete files and folder on Linux.

/bin/rm: Argument list too long.

The problem is that when you type something like rm -rf *, the * is replaced with a list of every matching file, like rm -rf file1 file2 file3 file4 and so on.

There is a relatively small buffer of memory allocated to storing this list of arguments and if it is filled up, the shell will not execute the program.

To get around this problem, a lot of people will use the find command to find every file and pass them one-by-one to the rm command like this:

find . -type f -exec rm -v {} \;

There is another approach we want to talk about now. Using this new method, We can delete at a rate of about 2000 files/second which is much much faster! You can also show the filenames as you’re deleting them:

find . -type f -print -delete

We hope this tip will come in handy when you have to delete a folder with a lot of files.