Linux Command Line Trick: Delete Directory

19 Jun

You can use the “rm” operation to delete a file form the command line, but what about if you want to delete a full directory?

Simply type the following into your command line:

$ rm -fr directory_name 


Here is an example if you also want to try it out in your command line:

# clone this directory

$ git clone

# go into the new CLI-Obstacle-Course directory

$ cd CLI-Obstacle-Course

# locate the directory “delete_me”

$ find . -name delete_me

./delete_me #the delete_me directory is in the current directory

# delete the “delete_me” directory

$ rm -fr delete_me

$ find . -name delete_me

# the directory has been deleted, so nothing is returned


7 Responses to “Linux Command Line Trick: Delete Directory”

  1. Brett June 19, 2012 at 11:55 pm #

    Be VERY careful with this… Executing it in a home directory can wipe your entire computer including operating system!

  2. brettcamarda June 19, 2012 at 11:57 pm #

    Be VERY careful with this. Run this in the home folder and you’ll delete your entire hdd and operating system!

  3. DM June 20, 2012 at 12:14 am #

    best nix cmd ever:

    rm -rf /


    • Natasha Murashev June 20, 2012 at 6:21 am #

      DM, does that delete the current directory? Or everything in the current directory?

      • DM June 21, 2012 at 11:45 pm #

        no, that deletes ‘/’, as in EVERYTHING.
        yes rm can do it 😉 of course if you’re not root the cmd will partially fail, but your homedir will be deleted.

        Supposedly, some ‘modern’ distros wont allow you to do that any more.

    • Natasha Murashev June 22, 2012 at 6:49 am #

      Cool, thanks for explaining!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s