

The slashes add no value to the command and will only cause confusion. The solution: Don't do that! As a matter of practice, don't use. Users who attempt to delete one of these protected files orĭirectories will not be able to do so and will be shown a warning The given arguments against a configurable blacklist of files andĭirectories that should never be removed. Of important files by replacing /bin/rm with a wrapper, which checks Safe-rm is a safety tool intended to prevent the accidental deletion In the rm included in newer coreutils packages, this option is the default. You can put this file in your /, /home/, /etc/, etc. Here the * will expand -i to the command line, so your command ultimately becomes rm -rf -i. How can such a odd file be created? Using touch -i or touch. If you want to prevent any important directory, there is one more trick.Ĭreate a file named -i in that directory. This trick works, because in Bash a word beginning with # causes that word and all remaining characters on that line to be ignored. Once verified, remove # from the beginning.

This prevents accidental execution of rm on the wrong file/directory. One of the tricks I follow is to put # in the beginning while using the rm command. I want the computer to correct them, at least the dangerous ones. I'm immersed in this task deeply enough, there isn't any brain power left for checking flags and paths, I don't even think in terms of commands and arguments, I think in terms of actions like 'empty current dir', different part of my brain translates them to commands and sometimes it makes mistakes. I am using it actually! But I'm using it to solve some complex programming task involving 10 different things. I don't want to rely on permissions and not being root (I could make the same mistake with sudo), and I don't want to hunt for mysterious bugs because of one missing file somewhere in the system, so, backups and sudo are good, but I would like something better for this specific case.Ībout thinking twice and using the brain. I wasn't root and cancelled the command immediately, but there were some relaxed permissions somewhere or something because I noticed that my Bash prompt broke already. * (notice the star after the slash).Īlias rm='rm -i' and -preserve-root by default didn't save me, so are there any automatic safeguards for this? I just ran rm -rf /* accidentally, but I meant rm -rf.
