Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Would this actually delete the entire hard drive? I know it would remove most things but how could rm remove itself?...
  1. #1
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845

    rm -rf /

    Would this actually delete the entire hard drive? I know it would remove most things but how could rm remove itself?
    Linux User #453176

  2. #2
    Just Joined! turrauko's Avatar
    Join Date
    Nov 2004
    Location
    Aberdeen, MD
    Posts
    2
    Well, obviously it won't delete the kernel as it is in use (and if I recall the current running kernel is protected). The same goes for some of the system files. Nonetheless, it will delete files that are required for functionality. So, in short, yes, it'll ruin your installation.

    I've never attempted to recover anything from a hard drive after this command was issued. It was just always fun to watch the thing go bye-bye only to start the long, tedius process of reinstalling the Operating System. But then again, that's the fun part isn't it?

  3. #3
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Yeah, I knew it would ruin the installation. I was just wondering about what would be left behind after
    Linux User #453176

  4. #4
    Just Joined! turrauko's Avatar
    Join Date
    Nov 2004
    Location
    Aberdeen, MD
    Posts
    2
    Well, like I said Kieren, it will continue to delete files as permitted by the kernel and the user's permissions. So, I suppose it would leave intact everything that wasn't wiped before the crash.

    You ought to try it! No, seriously, test it out in Bochs or QEMU. Then mount the image file as a loopback device and see what you can get out of it.

  5. #5
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    I think I might do when I get some time. I think I have a small HDD somewhere I can test it on
    Linux User #453176

  6. #6
    Just Joined! turrauko's Avatar
    Join Date
    Nov 2004
    Location
    Aberdeen, MD
    Posts
    2
    Sweet! Let us know! Thanks.

  7. #7
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,340
    Quote Originally Posted by Kieren View Post
    Would this actually delete the entire hard drive? I know it would remove most things but how could rm remove itself?
    If you mounted partitions from other drives or mounted shared resources via samba, nfs etc, they can also be deleted, so be careful when experimenting with that command.

  8. #8
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Ah, good point!

    I might just set up a spare computer with DSL on it to test it. I was thinking of a little project of making a case out of something. Was just reading Envador.com | Innovative concept cases which looks quite cool and I do have an old guitar at home I could use...
    Linux User #453176

  9. #9
    Just Joined! turrauko's Avatar
    Join Date
    Nov 2004
    Location
    Aberdeen, MD
    Posts
    2
    Quote Originally Posted by Kieren View Post
    Ah, good point!

    I might just set up a spare computer with DSL on it to test it. I was thinking of a little project of making a case out of something. Was just reading Envador.com | Innovative concept cases which looks quite cool and I do have an old guitar at home I could use...
    The only problem with that is with Damn Small Linux you won't be able to actually look and see what is left. So, just unplug the IDE ribbons from the main hard drive that you're using. No worries.

  10. #10
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,228
    rm can indeed remove itself.

    When a program is executed, its instructions and environment are loaded onto the stack and processed. The executable file that you ran doesn't actually need to exist any longer. For instance, try running this script:
    Code:
    #!/bin/bash
    
    echo "My filename is $0"
    rm "$0"
    echo "I'm still here!"
    The last echo statement will appear, despite the fact that the script has now vanished. Doing the same thing in C (deleting the binary) performs the same effect.
    DISTRO=Arch
    Registered Linux User #388732

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •