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.
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 likerm: 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 botchedrm
command, you might as well put asleep
statement in your alias... – frostschutz Sep 26 '21 at 19:48rm
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