Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: [SOLVED] Accidental sudo rm -rf /

  1. #1
    Join Date
    Sep 2007
    Location
    London, UK
    Beans
    529

    [SOLVED] Accidental sudo rm -rf /

    I'm not sure whether this should go in the beginner's section or in the general help section, but I did something very noobish.

    You see, I had a home backup on an external hard drive from a couple of months back when I was about to install the new ubuntu. I was in need of space on my hard drive so I decided to move some files to my external hdd, but it was out of space too. So I decided to delete the backup since the install was running fine and the backup was no longer necessary. The thing was that when I tried deleting the folder, only about 2gb of data (out of 34) could be deleted at a time because of the limited size of the wastebasket (it can only be as big as the amount of free space available on the /home partition). This would have taken too long.

    I couldn't figure out how to delete without sending to wastebasket first using the GUI, but then I remembered the command sudo rm -rf. I thought this was a perfect moment to make use of the terminal command.

    So, I right clicked on the "homebackup" folder and selected "open terminal here." I then proceeded to type sudo rm -rf /* because I thought it would delete everything IN THE DIRECTORY I HAD GONE INTO (it turned out later that the command continues doing what it is supposed to, irrespective of the directory the terminal is in). I had my doubts when the terminal said something about "read-only permission" so I closed the terminal. The process seemed to continue, however, and there were some unexpected changes (file manager seemed to revert to a different style, firefox crashed, rhythmbox attempted playing 20 songs at once, etc - what you see in youtube videos about sudo rm -rf). I then decided to check and make sure I wasn't imagining this. I opened my home folder and saw that there was 3.7gb free as opposed to the 2.4gb free there was earlier. That is when I turned off my computer (manually, because the option in ubuntu was greyed out).

    I tried rebooting, but GRUB came back with "Error 15." I need help. First of all, is there any way of knowing what files were deleted? (like a change log or something - or is the deleting in a random order) What will I have to do to return to normal or will I have to start everything afresh? If I have to start afresh, can I salvage some of my more important files?

    Thanks in advance for your help and cooperation

  2. #2
    Join Date
    Jul 2008
    Location
    Birmingham, England
    Beans
    2,400

    Re: Accidental sudo rm -rf /

    It's very likely you've lost everything essentially wiping your drive.

    sudo = assume root
    rm = remove
    -rf = delete everything inside the directory and force it to go without asking for confirmation
    / = root folder, has everything in

    If you need to delete /home/user do
    Code:
    rm -rv ~
    which will show you what it does after asking for confirmation.

  3. #3
    Join Date
    Mar 2008
    Location
    Cracow in Heart
    Beans
    1,938

    Re: Accidental sudo rm -rf /

    hi and my sympathy

    you can access your remaining files via the Live CD:

    http://godawski.oxyhost.com/accesshd.html

    and then I would reinstall.
    Keep it real. Keep it nice.
    [SIGPIC][/SIGPIC]Shooting Ubuntu



  4. #4
    Join Date
    Apr 2008
    Location
    AZ
    Beans
    2,072
    Distro
    Ubuntu

    Re: Accidental sudo rm -rf /

    try testdisk. boot off a liveCD install testdisk from the repos.

    http://www.cgsecurity.org/wiki/TestDisk

    TestDisk is a powerful free data recovery software! It was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses or human error (such as accidentally deleting a Partition Table). Partition table recovery using TestDisk is really easy.

    TestDisk can

    * Fix partition table, recover deleted partition
    * Recover FAT32 boot sector from its backup
    * Rebuild FAT12/FAT16/FAT32 boot sector
    * Fix FAT tables
    * Rebuild NTFS boot sector
    * Recover NTFS boot sector from its backup
    * Fix MFT using MFT mirror
    * Locate ext2/ext3 Backup SuperBlock
    * Undelete files from FAT, NTFS and ext2 filesystem
    * Copy files from deleted FAT, NTFS and ext2/ext3 partitions.

    TestDisk has features for both novices and experts. For those who know little or nothing about data recovery techniques, TestDisk can be used to collect detailed information about a non-booting drive which can then be sent to a tech for further analysis. Those more familiar with such procedures should find TestDisk a handy tool in performing onsite recovery.

  5. #5
    Join Date
    Aug 2006
    Beans
    13,354
    Distro
    Ubuntu Mate 20.04 Focal Fossa

    Re: Accidental sudo rm -rf /

    I think there is no other option but to reinstall. Try recovering some of the files with photorec. http://www.cgsecurity.org/wiki/PhotoRec

    Edit: In oder to delete a file/folder without sending it to trash, highlight the items you wish deleted and hit shift+del.
    Last edited by mikewhatever; January 1st, 2009 at 03:36 AM.

  6. #6
    Join Date
    Jun 2006
    Location
    Texas
    Beans
    3,930
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Accidental sudo rm -rf /

    Quote Originally Posted by nhasian View Post
    Quote Originally Posted by mikewhatever View Post
    Try recovering some of the files with photorec. http://www.cgsecurity.org/wiki/PhotoRec

    +1 to both. Available on the SystemRescueCd
    UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. -- Doug Gwyn
    SystemRescueCd | Dual Boot | psychocats | FAQ

  7. #7
    Join Date
    Sep 2007
    Location
    London, UK
    Beans
    529

    Re: Accidental sudo rm -rf /

    Well, by the time I turned off my computer only 1.3 gb (from the home folder) seemed to have been deleted so is all still lost? Can I not still recover some word documents, etc if they were not deleted? Or does what was deleted render my hard drive unreadable?

    But either way, it looks like I'm going to have to reinstall. Does the fact that I had / and /home on different partitions change the situation in any way? As long as I can recover some more important documents, its not such a big loss. Thanks for your help so far, guys

  8. #8
    Join Date
    Mar 2008
    Location
    Cracow in Heart
    Beans
    1,938

    Re: Accidental sudo rm -rf /

    I guess you nuked your / partition so the root partition not your /home.

    Try to access it via the guide I posted above.
    Keep it real. Keep it nice.
    [SIGPIC][/SIGPIC]Shooting Ubuntu



  9. #9
    Join Date
    Aug 2006
    Beans
    13,354
    Distro
    Ubuntu Mate 20.04 Focal Fossa

    Re: Accidental sudo rm -rf /

    You may be able to recover all of your personal files. The fact that root and home are separate should make it easier. You'll probably want photorec to copy files from home to the external HDD, so make sure there is enough space there.

  10. #10
    Join Date
    Nov 2006
    Location
    40.31996,-80.607213
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Accidental sudo rm -rf /

    I wouldn't be so sure. The fact that he was running it for /* is enough to say that it can descend into /home and delete files also. At least, that is my assumption.

    To the OP, my sympathy.
    You may try booting from a LiveCD and attempt to recover that which is not deleted. After that, reinstall and pay a little more attention to your commands from now on. Once, I deleted my /boot directory on total accident, and was able to rebuild it all without (totally) panicking and rebooting. (Must be a windows mindset to reboot in panic!)

    Dr Small
    "Security lies within the user of who runs the system. Think smart, live safe." - Dr Small
    Linux User #441960 | Wiki: DrSmall

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

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