How does one delete a directory filled with files and other subdirectory permanently, bypassing the trash, from the command line in OS X?

40,824

Solution 1

If you want to delete foo/bar, the command you want is rm -r foo/bar (assuming you are working in the directory that contains foo). This will delete bar and everything in it, but leave foo and anything else in it alone.

rm -r is clever enough not to recurse into ../ - otherwise every rm -r would delete everything.

Solution 2

If you run:

rm -r

without passing it a directory/file argument, nothing will happen.

There is no difference between:

rm -r xyz
rm -R xyz
rm -r xyz/

etc.

Share:
40,824

Related videos on Youtube

Jon
Author by

Jon

Updated on September 17, 2022

Comments

  • Jon
    Jon almost 2 years

    So my command line skills are a little rusty and I'm having trouble remembering the differences between the meanings of flags in different distro's os's. I also don't really remember all my technical lingo so manpages seem really unclear.

    Basically I'm on Mac OS X and want to delete a directory along with all of its contents. What I'm mainly concerned about, I suppose, is that it'll delete literally ALL of the references within the directory, including ../ and ../<everything else, including ../'s own ../> and then just totally screw up my entire system.

    Which of these do I want to run?

    $ rm -R dir-name/
    

    or

    $ rm -r
    
    • HikeMike
      HikeMike over 13 years
      Jon, please click the checkmark next to one of the responses if they answer your question. This will mark your problem solved and reward the person answering.