How to sort out - bash: /bin/rm: Argument list too long

When running rm * in a directory that contains a lot of individual files might get the following error:

  1. bash: /bin/rm: Argument list too long

There are a few ways to delete the files inside that specific directory:

  • You could delete the whole folder
  • You could the find command - this is my personal favorite
  • Or use a for loop - much slower!

Here’s how to do that!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
February 8, 2020
Accepted Answer
  • Option 1:

Let’s say that you don’t need the folder, so what you could do is just use rm -r to delete the folder recursively, that way you would basically supply just 1 argument (the folder name), and you will be able to delete the folder and all files inside:

  1. rm -r folder_name
  • Option 2:

Use the find command, the benefit is that it is much quicker and you could add specific arguments to narrow down the risk of deleting something that should not be deleted:

Again, first cd into the folder in question and then run:

  1. find . -maxdepth 1 -type f -name "temp_file_name_*" -delete

A quick rundown of the arguments:

  • -maxdepth - here we specify the levels of directories below the starting-points that you would like to go. In our case 1 means that we would only delete the files from the current directory and not the subfolders
  • -type f - this is how we specify the type of the files that we would like to delete, this is really beneficial as if there are any symbolic links they would not be deleted
  • -name - we specify the file name with a wildcard at the end that we could use as a pattern
  • -delete - with the delete argument we basically tell the find command what to do with the files that match the patterns above.

In most cases, this should be fairly quick.

  • Option 3:

You could use a for loop to delete the files inside the folder with the rm command, note that this could take a very long time so I would not really recommend it:

You would need to first cd into the folder and then run:

  1. for i in * ; do rm ${i} ; done

Note that this would delete all files inside the directory.

Here’s a quick video on how to do that as well:

Hope that this helps! Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel