Include warning to shell when user runs dangerous command

The other day I came very close to wiping my system after entering rm -rf /* in the terminal. I’m pretty sure that some individuals have also ran into this too. Maybe some weren’t even as fortunate as me and suffered serious casualties after.

Can we have some kinda clear warning pop up before the command runs?

Like a This command would wipe your entire system. Proceed: yes/no

What was your intention of running that command? What did you want to accomplish? What did you think it will do? Where did you get that command? Who told you to run it?

What happened? What did stop you?

I just ran it, and don’t advise others try :laughing:

It was on a snapshotted VM of course, so no issue. Whilst without sudo it did nothing to system areas, it totalled my home folder and no doubt any other area not requiring sudo.

I wouldn’t necesarily be opposed to a warning, you know, something like:

$ rm -rf /*
Attempting to delete entire system...
Are you out of your Vulkan mind?! yes/[no]

Having accidentally trashed my /bin folder in the past, I hopefully learned my lesson… but it can be a hard one to have to learn and potentially devastating in personal folders get involved.

Oh, and welcome to the community @willy_wonka_28 :wave: :smiling_face_with_sunglasses: :enos_flag:

Why not running it with sudo while you had the chance :laughing:

Where would the fun be in that? Seriously, how do people learn if they don’t touch the stove? Live and learn, and then you know what not to do.

rm has two parameters that might help you

-i     prompt before every removal
-I     prompt once before removing more than three files, or when removing recursively; less intrusive than -i, while still giving protection against most mistakes

So, if you want to use -I you could define an alias

alias rm=`rm -I`

in bash

I never tested it but there is even an AUR package safe-rm for this.

as pointed out there is a interaction function in RM that can easily be added to your bashrc file.

Yes we have all suffered the misfortune of typing in a command and it destroying something we didn’t want it to. Right after we LEARNED very quickly that we need to JUST PAY ATTENTION.

This is why its important to have backups.

Exactly (JUST PAY ATTENTION), I certainly don’t want my system to start 'Are you sure?'ing me.

Had a system like that they called it Windows. I deleted that garbage immediately :rofl:

:sweat_smile: It was a mistake on my path…was trying to delete all the files in a directory. I realized something was wrong when I started reading the error messages in my terminal.

Thanks for the welcome Bink! It’s been nice using endeavour os for sometime…Windows was out to take my ancient computer’s life.

thanks for this.

Welcome!

Please note that rm is not the only command that can cause issues. For example, cp and mv can have the potential to create nasty problems. Option -i can try prevent accidents with those commands.

Many other commands (like partition managers and dd) have the potential for disasters too.

Tools like safe-rm might be useful to some extent, but as already implied here, it is best to be aware and be careful.

Manuel, never forget the most dangerous of all, dd. It still bites me on occasion when I’m not being careful hahaa, but I thought that was the correct device name for my flash drive..oops!

Use your sudo wisely and cautiously!
With great power comes great responsibility. And that responsibility is yours only.

Thanks for the suggestion!

I think this is a good idea but probably not that practical.

The biggest problem would be coming up with a list of dangerous commands that we could all agree on. Something I feel would be a dangerous command someone else might disagree with.

Additionally, given the makeup of our userbase, I think many would find this type of warning to be intrusive.

And frankly, you can do great damage with cat if you put your mind to it.
Well and running with root privilege, I guess anything…

Cat - I agree, lost two keys to the claws of mine :rofl:

I use the trash-cli package, which protects from some things, but I doubt would stop a full blown attack of idiocy (we have all done something similar) - the only real solution is good backups.