Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
1  
It isn't of infinite depth because you did not let the loop run forever... –  psusi Jun 12 '12 at 23:18
1  
@psusi I was using "infinite" in the way that Borges uses "infinite" in "La Casa de Asterión" ;) –  CaldwellYSR Jun 12 '12 at 23:19
    
@CaldwellYSR Anyone trying to help you with a technical issue would prefer that you be exact and correct and leave the literary embellishments for a more appropriate setting. –  jw013 Sep 27 '12 at 17:29
add comment

3 Answers

up vote 5 down vote accepted

Try rm -rf to avoid the prompting.

-f, --force           ignore non-existent files, never prompt
share|improve this answer
    
YES! I love you very much. By the way it took two tries to work. The first time it said "Directory is not empty" but then if I did it again it worked. –  CaldwellYSR Jun 12 '12 at 23:15
    
@CaldwellYSR: Great to hear it worked. It's the kind of problem I also could've gotten myself into. –  Kafuka Jun 12 '12 at 23:39
1  
Did you find out why you got the prompt? It looks like the directory was owned by you, so there should have been no need to use sudo. Using sudo in combination with rm -rf is potentially very dangerous. –  Jari Laamanen Jun 13 '12 at 9:45
add comment

A very secure way would be - if your find supports -delete - to use find for deleting:

find -type d -name 27-Jan -empty -delete

Since -delete implies -depth, it will first walk down the tree to directory 3275, delete it, step up one step, now 3274 is empty too, and can be deleted, step up to 3273 and so on...

man find:

   -depth Process each directory's contents before the directory itself.
          The -delete action also implies -depth.
share|improve this answer
    
Interesting... I'll upvote it because I don't see any reason why it wouldn't work. Since I already managed to delete them though I'll keep the accepted answer above. Thanks for this though –  CaldwellYSR Jun 12 '12 at 23:54
add comment

You can remove directory hierarchies recursively using -r switch of rm

-r, -R, --recursive
              remove directories and their contents recursively

So issuing

rm -r 27-Jan

should get rid of the directory. Unless you have already tried that, of course. In that case, could you specify the error you get?

share|improve this answer
    
I've tried that, I edited my question to show what I've tried (besides moving to .Trash) –  CaldwellYSR Jun 12 '12 at 23:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.