0

I am trying to delete a folder that is used in my cdn and it creates new folders for each file viewed. This means that for every file requested their is a folder. This has stacked up to about a 100 million folders inside my main folder.

How would I go about deleting all of the contents inside? Because when I try rm -rf it gives me the error of Argument List too Long.

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
  • 5
    What is your exact command line? Because `rm -rf` by itself doesn't do anything. What arguments are you providing? – larsks Aug 21 '17 at 16:26
  • 2
    Exactly what you're trying to delete is a little unclear. You're saying "go about deleting all the contents inside" but your title says, "deleting a folder and all its contents". If it's the folder and it's contents, just use `rm -rf folder_name`. That deletes `folder_name` and everything inside of it. – lurker Aug 21 '17 at 16:29
  • Possible duplicate of [delete file in linux?](https://stackoverflow.com/questions/44952355/delete-file-in-linux) – dlmeetei Aug 21 '17 at 17:37

1 Answers1

0

Your post is bit confusing and certainly belong to serverfault but..

Probably, what you are trying to do is something like:

rm -rf *

The error message "Argument List too Long" is from bash that have a fixed memory size for argument list. So when you run rm -rf *, bash first create a list of every file/folder before deleting them. To see the size:

getconf ARG_MAX

If you want to delete the entire folder, just rm -rf folder/* should work.

But if you want delete files inside folder.

find /folder/ -type d -exec rm -rf {} \;

This every directory found (-type d) with find you be removed one by one.

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
Joao Vitorino
  • 2,976
  • 3
  • 26
  • 55