How This Bash Can Break My OS?

Hi there,
I’m currently exploring the freeCodeCamp Bash Boilerplate lesson, and in one step, it says:

Looks like it’s gone. Surely, it went to the trash can right? No, it’s just gone. You should be very careful when recursively removing files like that. It will delete everything, and can destroy your operating system.

I have a question:

How exactly can a Bash command break my OS within my project or work folder? I understand it can happen if run as root on the root directory, but can it also break things outside the root or just within a folder?

it depends on the command you run, and what you specify after rm -rf

if you write the path to the root folder it would delete everything in it, even if you are not in the root when running the command

can it really do that? :thinking:
Hmm… sounds wild. Might be fun in a virtual machine someday just to see how it breaks things :joy: (not my main OS tho!)

here for your amusement

https://askubuntu.com/questions/604324/how-is-rm-rf-able-to-delete-all-files-in-the-system

Thanks a lot for the link! I’ve got another question now:
Does Bash have any sort of backup, undo, or redo feature? Or is there any way to stop a command if we run something by accident, or does only Ctrl + C work in that case?

no, there isn’t an undo generally
you can stop a process with Ctrl + c but what is arleady done is done

1 Like