Argument list too long (Bash: /bin/rm) - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

Argument list too long (Bash: /bin/rm)
======================================

### [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on October 20, 2022 
Updated on September 18, 2024 · 1 minute read

1. [The error and problem](#content-the-error-and-problem)
2. [Why this happens](#content-why-this-happens)
3. [The solution](#content-the-solution)

[\#](#content-the-error-and-problem "Permalink")The error and problem
---------------------------------------------------------------------

Sometimes you can encounter this error when executing a `rm ./directory/*` inside a directory to clean it up:

 ```
$ bash: /bin/rm: Argument list too long

```

[\#](#content-why-this-happens "Permalink")Why this happens
-----------------------------------------------------------

This is because of the `ARGS_MAX` setting in your operating systems config, which defines the maximum argument size a command can accept. The solution is to not use a wildcard in your command:

 ```
rm ./directory

```

But the downside to this, is that you're now deleting the directory as well. And most of the times you don't want this. Because then you need to recreate the directory again and you have to take in account of the persmissions the directory previously had.

[\#](#content-the-solution "Permalink")The solution
---------------------------------------------------

The solution is to use the `find` command, which can perform actions directly inside a directory and only on the files. This way you don't need to use a wildcard (which would introduce the same problem):

 ```
find ./directory -type f -delete

```

You can even make it more specific to only delete certain files, in this example to only delete log files:

 ```
find ./directory -name '*.log' -type f -delete

```

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

- [How to install Composer packages locally](https://rocketeersapp.com/knowledge/install-composer-packages-locally)
- [How to send GET and POST requests with curl](https://rocketeersapp.com/knowledge/curl-post-get-api-requests)
- [Essential Linux command line basics for developers](https://rocketeersapp.com/knowledge/linux-command-line-basics)
- [How to search file contents with grep](https://rocketeersapp.com/knowledge/search-files-grep-command)
- [The complete guide to the curl command](https://rocketeersapp.com/knowledge/curl-command-complete-guide)
- [Getting started with the AWS CLI](https://rocketeersapp.com/knowledge/getting-started-aws-cli)

 [View all 21 articles →](https://rocketeersapp.com/knowledge/command-line)
