When running rm *
in a directory that contains a lot of individual files might get the following error:
- bash: /bin/rm: Argument list too long
There are a few ways to delete the files inside that specific directory:
find
command - this is my personal favoriteHere’s how to do that!
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!
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.
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: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: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 thefind
command what to do with the files that match the patterns above.In most cases, this should be fairly quick.
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: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