How do you delete a folder and all contents in Terminal?

Posted:
in macOS edited January 2014
Sometimes I run across a folder that I want to delete, but the items inside are locked or owned by root so I can't delete them unless I use the terminal. I manage to finish eventually, but I have to sudo rm everything individually, then sudo rmdir all the empty folders. Is there anyway to delete one folder and all of the contents?

Comments

  • Reply 1 of 9
    mcqmcq Posts: 1,543member
    Taking a glance at the man pages, I'm guessing "sudo rm -r" would do the trick?



    [ 03-09-2003: Message edited by: MCQ ]</p>
  • Reply 2 of 9
    snofsnof Posts: 98member
    [quote]Originally posted by MCQ:

    <strong>Taking a glance at the man pages, I'm guessing "sudo rm -r" would do the trick?



    [ 03-09-2003: Message edited by: MCQ ]</strong><hr></blockquote>



    Ah, my favorite command...



    You should be very careful with that, I don't reccomend doing it at the root level of your drive, unless you don't like you data.
  • Reply 3 of 9
    scottscott Posts: 7,431member
    Yes do read the man page



    &gt;man rm
  • Reply 4 of 9
    amorphamorph Posts: 7,112member
    [quote]Originally posted by Snof:

    <strong>



    Ah, my favorite command...



    You should be very careful with that, I don't reccomend doing it at the root level of your drive, unless you don't like you data. </strong><hr></blockquote>



    At least rm -r prompts you for each file it intends to delete.



    rm -rf is the spawn of the devil.
  • Reply 5 of 9
    mcqmcq Posts: 1,543member
    lol, so is that the correct command? Or is there some safer command that does the same thing?
  • Reply 6 of 9
    rm -dR



    That will do it.



    -d for directory



    -R for recursive.
  • Reply 7 of 9
    scottscott Posts: 7,431member
    [quote]Originally posted by MCQ:

    <strong>lol, so is that the correct command? Or is there some safer command that does the same thing?</strong><hr></blockquote>





    Well if you would READ THE MAN PAGE you could see what all the options do.
  • Reply 8 of 9
    mcqmcq Posts: 1,543member
    Ok, heh thanks for the prodding I suppose... I had read it before but missed the other option for prompt on delete.
  • Reply 9 of 9
    os10geekos10geek Posts: 413member
    You should check out the thread in Genius bar about this exact subject...
Sign In or Register to comment.