0

So it already happened to me once, I was trying to run

rm -r ~/.emacs.d

But accidentally hit enter at just the wrong moment.

rm -r ~

Luckily I run into protected files before deleting everything, and was running it in a fairly new Termux enviornment instead of my main computer. However, on that main computer I was just trying to run

rm -r ~/.go ~

(I originally tried rm -r ~/.go ~/.config/go but then saw with highlighting that the latter isn't a thing, obviously, and accidentally hit enter instead of backspace, at just the worst moment).

Again, I was spared by protected files and thank god the fact ~/.go was first.

At any case, I would really like to avoid such danger; my thought is that maybe I could use some magic option with an alias or define my own rm() function so ~ will act similarly to /. Alternatively unix magic is also fine.

Of course, the obvious solution is to just get into the habit of always cd ~ first and remove with relative paths, but I would like a quicker solution so I won't die of a heart attack while trying to form it.

  • Stupid idea, alias rm -r ~ to echo ""? – Grace Thompson Sep 26 '21 at 19:22
  • 5
    Does this answer your question? Safe Directory Delete – Kusalananda Sep 26 '21 at 19:24
  • is this a school assignment? – jsotola Sep 26 '21 at 19:28
  • rm just does not have much to offer here, it either asks always, or once but only if it's more than 3 files (weird combo) or recursively. And a prompt like rm: remove 1 argument recursively? just is not very helpful without telling you what the argument is, so it could be anything after shell expansion and variables. rm -i (always ask) would be fine if it had a "yes to all" answer but it does not, it really asks for every file... but at least it tells you the file name. If you just want to be able to ^C a botched rm command, you might as well put a sleep statement in your alias... – frostschutz Sep 26 '21 at 19:48
  • If you want to protect your homedir specifically, you could make the first file inside it be the protected file, so rm would ask first and not delete anything. But this relies on implementation a lot and might not persist long term, so it would be a risky hack. – frostschutz Sep 26 '21 at 19:52
  • You're committing UTBLT! (Using Tool Before Learning Tool) (Using Thing Before Learning Thing). The Whack-A-Mole strategy for defanging commands is poor. Linux is a powerful tool that will let you shoot yourself in the foot. Learn to aim. – waltinator Sep 26 '21 at 21:14
  • As referenced on a now-deleted answer, please read this too - Why is aliasing over standard commands not recommended? – Chris Davies Sep 26 '21 at 22:08

0 Answers0