When I feel like scrapping the whole project and starting over:

Me: (in the project dir) sudo rm -rf /*
Me: (after waiting a while) Something feels off… Why is it taking so long to delete everything?
Me: (suddenly realizing) ^C ^C ^C
System: Press any key to continue…

当我想把整个项目推倒重做时:
我:(在项目目录)sudo rm -rf /*
我:(等了一会儿)有点不对劲。。。怎么删了这么长时间还没删完
我:(恍然大悟)^C ^C ^C
系统: Press any key to continue…

  • @[email protected]
    link
    fedilink
    English
    3•14 hours ago

    I did sudo apt purge to remove an extra desktop environment. Then i found out that it also deletes dependencies.

    Thankfully i was able to save the output of the command and then used python to parse and construct an apt command to reinstall all the things.

    I felt both stupid and smart at the same time

  • @[email protected]
    link
    fedilink
    6•16 hours ago

    This joke has been out of date for over a decade because the --preserve-root flag is enabled by default in most (all?) distributions.

  • @[email protected]
    link
    fedilink
    1•13 hours ago

    I restored a system once by kubeexec into a running pod after someone did this on the host. It was … Strange.

  • @[email protected]
    link
    fedilink
    English
    1•13 hours ago

    Fun fact, did you know that undefined varuables in Makefiles are substituted for “”? So be careful when copypasting some code from your previous Makfefile and make sure to use guardrails like ./$(VAR)

    In the end I ran rm -rf, lost half of my $HOME and did not touch my laptop for a few days. Too bad it ran from inside Neovim. Could have noticed sooner.

    • just another devA
      link
      fedilink
      English
      1•2 hours ago

      I think that was the cause of a few wipes of a few wipes by a buggy nvidia uninstall script back in the day. “Whoops.”

  • @[email protected]
    link
    fedilink
    1•19 hours ago

    This is apparently a joke! But I have done this in real life. It’s an honest mistake you can make if you’re experienced, fast, complacent and careless. Always be prepared for it. Here are some tips:

    1. Don’t use sudo for anything other than system operations. Not even for editing configuration files.

    2. Never put any development/sysadmin projects under ownership of root. Always develop the project under your personal unprivileged user account. Use sudo only for the final deployment of project to system directories.

    3. Use sudoedit to edit any system configuration files.

    4. Avoid ./* at all times in favor of just *. While this is counterintuitive, this is actually safer. You will have less habitual urge to type the / alone by accident.

    5. Avoid the -f flag in all instances for any command until some operation fails. That will leave you with enough time to reflect on your mistakes when you make one.

    6. Always keep a data recovery plan. Backups are highly recommended. If you use Btrfs partitions, you can make periodic read-only snapshots of your critical data. You can automate this process with a tool like Snapper.
      Btrfs snapshots store de-duplicated data. So each snapshot stores only the changes from the previous one. It doesn’t use a lot of space, even when backing up large media files. You’ll still get the chance to recover your data at the time of the last snapshot.

    7. Most operating system files aren’t critical data and don’t need to be backed up. Backup the system configuration files in /etc and the package installation list if your package manager facilitates it.

    8. This is optional, but useful in case your Linux installation gets nuked somehow, including this nonsense.
      You can always reinstall the distro and start over again. But often times, you can trivially recover the installation by booting from a live USB/CD and doing some manual repair. Learn to chroot into your nuked root partition and operate from inside it.
      Most live disks give you an option to repair an installation, in case you deleted the root partition by accident. You can also repopulate the deleted files using commands like debootstrap and pacstrap.

    • @[email protected]
      link
      fedilink
      2•18 hours ago

      Another tip: use rmdir to remove empty directories instead of rm -rf. rmdir fails if the dir turns out to still contain some files. This way you’ll mitigate the risk of accidentally nuking a directory full of important data.

  • @[email protected]
    link
    fedilink
    10•1 day ago

    Me who wants to remove a system-wide script:

    rm -rf /usr/bin /local/script.sh

    Yes, the space was an accident, and yes, this did happen 😋

  • @[email protected]
    link
    fedilink
    English
    2•
    edit-2
    1 day ago

    One time I ran rm on a directory and it started deleting files on the NAS mount I had in that directory and forgot about. So note to self: do not mount things inside project directories

  • @[email protected]
    link
    fedilink
    21•
    edit-2
    2 days ago

    `mv folder delete-this

    rm -rf delete-this`

    gives you one chance to reconsider what you just did before it is too late. And you never have a risk of a dangerous delete-all lurking in your command history.

    • @[email protected]
      link
      fedilink
      1•13 hours ago

      Or rm -rf dir instead a relative path. Write down the actual path or directory name you want to delete. Do not use only variables for the path. But combining with literals is fine, such as dir/${subdir}/* . One can also test if the directory exists before starting the process, especially useful in scripts. And I recommend using --verbose option to see what is being deleted: test -d dir && rm -rfv dir

    • @[email protected]
      link
      fedilink
      8•23 hours ago
      rm -rf /*
      

      This deletes everything in root; a great way to break your OS and lose all data too.

      OP meant to run

      rm -rf ./*
      

      Note the period, which represents the current directory. So this deletes everything in the current directory instead of the entire filesystem

      • @[email protected]
        link
        fedilink
        2•13 hours ago

        This deletes everything in root; a great way to break your OS and lose all data too.

        Nowadays rm command will prevent doing this, without option --no-preserve-root .

        • @[email protected]
          link
          fedilink
          1•
          edit-2
          20 hours ago

          Why not just:

          rm -r *
          

          What is the necessity of that sudo, -f and /?

          Disclaimer: I have carelessly committed this nonsense too. Thankfully, the important data was backed up. I used a live USB to access the nuked OS partition and used chroot to repopulate the deleted system files. Didn’t even have to reinstall the OS.

          Always have a disaster plan. If you have a btrfs partition, even periodic btrfs snapshots are a cheap lifesaver. Everything else can be saved like a breeze with some terminal magic.

  • pelya
    link
    fedilink
    20•2 days ago

    Why do you need sudo to run your project? Are you developing kernel drivers?