Removing Infinitely Nested Directories

directoryosxrm

Let me start off by saying this is a Mac Terminal I'm using. Not Linux, but I assumed I would get the best answers here as it has to do with Unix and the command line not really anything about Mac itself.

Anyways here's the problem. In an attempt to be extremely lazy, I tried to write a function in my ~/.bashrc that would let me move into a "homework" folder, created a folder with today's date, move into said folder, and open vim with the given filename… all in one go. It looked something like…

export DATE="$( date +%d-%b )"
function hw() {
  cd ~/Java/Programs/HW
  mkcd $DATE
  vim "$*"
}

mkcd is a function that makes the folder and moves into it at the same time. This is what my function looks like now and it works just fine. However in on of my many attempts to make this work I made a really really stupid error and ended up with some kind of infinite loop with my mkcd part… still not sure how I managed this and I've since deleted that code. Well what happened when I did this is quite obvious… I now have a folder named 27-Jan that has infinitely many folders named 27-Jan inside of it. (Like I said really stupid)

Well to make it stop putting me deeper and deeper I hit ^c and viola I stopped… I changed back to my ~/ folder and did a quick sudo rm 27-Jan/. To my amazement (and worry) that didn't work. I tried a for more things to get rid of it but nothing did anything. So being clever like I am… I moved it to .Trash and stopped worrying about it. Since then I have emptied my trash a few times and never really noticed but that bloody folder won't go away! It's taking up zero bytes on my hard disk but it's still there with all it's little sub folders.

What I've Tried:

sudo rm 27-Jan/
sudo rm -r 27-Jan/ 

This one said override rwxr-xr-x caldwell/staff for 27-Jan/(many times repeated)/27-Jan? To which I've responded y and yes and even si (in case it spoke spanish)… everytime it says No such file or directory and repeats the previous question.

Has anyone ever seen anything like this? And do you know what I might be able to do to make it just go away?

Best Answer

Try rm -rf to avoid the prompting.

-f, --force           ignore non-existent files, never prompt
Related Question