How to remove a directory recursively?

Discussion in 'Command Line' started by carbon333, Feb 16, 2012.

  1. carbon333

    carbon333 New Member

    Messages:
    87
    Likes Received:
    6
    Trophy Points:
    0
    By typing in the terminal:

    rm -rf /path/to/the/directory

  2. rpatt

    rpatt New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    You do need to make sure that you have write permissions to remove the directory, sub directories. If you run into permission problems, you can do

    chmod -R +w directory-name

    and then

    rm -rf directory-name
  3. forestplay

    forestplay New Member

    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Be aware that 'rm -rf directory-name' is powerful. As in, dangerous. Use with caution.

    -Bob "Know from experience"
  4. ehansen

    ehansen New Member Staff Writer

    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    The meanest prank to pull on a Linux beginner is getting them into root and telling them to run "rm -rf /".

    Also, this works too:
    find . -exec "rm -rf {}"\;

    I believe that's the command anywho. Been a while since I used find's exec switch.
  5. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    214
    Trophy Points:
    43
    I have a rule that I always type in the full path to whatever i'm using 'rm -rf' on.. I'll also preach it to anyone i'm teaching..

    IE: if you're root and you are in /home/rob/Downloads/ and want to remove the /home/rob/Downloads/etc/ directory, type in the full path to it.. you don't want to accidently wipe out /etc/ :)

    (also, don't run around as root unless you have to!)

Share This Page