Contents
Does rm require root?
Set that script to ownership root:your_group and permissions 760 so that you must sudo in order to execute rm and you will not need to be root to write or read the file. You can then also get around this script by simply using /bin/rm instead of rm, but you’ll do that knowingly.
What does rm — no Preserve root do?
If there is no –preserver-root directive (bypassed or default), rm will attempt to delete everything on the system. Note that it will always fail to do so as there are many files which it will not be able to delete because they are open.
How do I recover my sudo rm?
When recursively deleting files starting from the root directory / as sudo there is no way other to recover the state of your OS as it was before than restoring from a backup. In case you don’t have a recent backup at hand you will have to reinstall Ubuntu.
When was no Preserve Root added?
Anyway, this is a relatively new restriction, it was added in the 7th version of the POSIX specification (the previous one is here), before that rm -rf / was a perfectly valid command.
Can you undo a rm?
Short answer: You can’t. rm removes files blindly, with no concept of ‘trash’. Some Unix and Linux systems try to limit its destructive ability by aliasing it to rm -i by default, but not all do.
How to prevent accidental rm-rf / * in Linux?
Deleting a directory from inside would be attractive, because rm -rf . is short hence has a low risk of typos. Typical systems don’t let you do that, unfortunately. You can to rm -rf — “$PWD” instead, with a higher risk of typos but most of them lead to removing nothing. Beware that this leaves a dangerous command in your shell history.
What should I do if I delete something with rm-rf no preserve root?
When you delete stuff with rm -rf –no-preserve-root, its nigh impossible to recover. It’s very likely you’ve lost all the important files. As @faker said in his answer, the best course of action is to transfer the files to a safe location and redeploy the server afterwards. Take backups weekly, or at least fortnightly.
What to do if you don’t use RM in shell?
The best solutions involve changing your habits not to use rm directly. One approach is to run echo rm -rf /stuff/with/wildcards* first. Check that the output from the wildcards looks reasonable, then use the shell’s history to execute the previous command without the echo.
What happens if you run Sudo RM instead of SUDO?
I accidentally executed sudo rm /* instead of sudo rm ./* inside a directory whose contents I wanted to delete, and I have basically messed up my system. None of the basic commands like ls, grep etc. are working, and none of my applications are opening, like chromium, slack, image viewer etc.