7 ms·
While this is good guidance for Emacs users, another, more shell-based tactic is to use the "-i" option for "rm" which requests a confirmation before deleting t
by kickingvegas 4y ago
While this is good guidance for Emacs users, another, more shell-based tactic is to use the "-i" option for "rm" which requests a confirmation before deleting the file. Aliasing "rm" to "rm -i" in either .bashrc or .zshrc (depending on what shell you use) for interactive operations has saved me a countless number of times from regret.
- marcosdumay 4y ago> Aliasing "rm" to "rm -i" in either .bashrc or .zshrc Or, alternatively, don't. People with that alias learning to add -f to every rm invocation are also a large source of problems. Rm should really do something more sensible on the -i switch, like displaying a summary or the files and asking for confirmation only once. Personally, I like to run "find -name file" and once I'm ok with it, I circle the command back and add -delete to it. It is much more usable.
- kickingvegas 4y agoFor such folks, telling them that invoking the full path of the executable will bypass the alias, e.g. “/bin/rm -f” will do the right thing. Discoverable? Nah. But we are talking about shell command behavior which is pretty arcane anyways.
- bravetraveler 4y agoNot really something I'd suggest with rigor, but prefacing an aliased command with a backslash will also defeat it
- dylan604 4y agoTIL. I was unaware of that. so if rm is aliased to "rm -i", then \rm will do the normal thing?
- avnigo 4y agoYou can also do that by prefacing an aliased command with "command".
- dylan604 4y agoi like the \ vs 7+space additional key presses. that's like typing the full path without utilizing tab expansion. only noobs do that /s
- bravetraveler 4y agoIndeed! I had to use this pretty routinely supporting a particular customer at a previous employer. Their shell profiles were littered with two-letter aliases, replacing quite a few common things with their proprietary [often unrelated] versions For example, mv for moving files became mv for Mail Volume, or something
- dylan604 4y agodearlordy, that's even worse. aliasing an existing cmd with options preset is one thing. aliasing a well known cmd to some esoteric cmd is mindboggling
- sshine 4y agoI’ve run with alias rm=‘rm -iv’ for years without adding -f. Much like I don’t prepend ‘sudo’ until it requires me, at which point I stop and think. Your ‘find -delete’ trick does the same: it creates time to think between expressing yourself and evaluating the outcome. This is great.
- naniwaduni 4y agoConsidering the difference between bare rm and rm -f is that interactive rm without -f is required to ask for each read-only file (which has approximately nothing whatsoever to deal with whether you can or should be deleting it!), I'm pretty sure learning to add -f to every rm invocation causes a median of 0 problems per person learning it.
- blooalien 4y ago> "Personally, I like to run "find -name file" and once I'm ok with it, I circle the command back and add -delete to it. It is much more usable." This is becoming more and more my favorite method as well. It's easy, it's reasonably safe, it's readable, and it works well.
- avnigo 4y agoAliasing "cp" to "cp -i" also prevents you from overwriting files without confirmation. It's more of a preference thing than a recommendation, but overwriting on copy is something that bit me in the past when working a bit mindlessly. I guess the proper recommendation would be "don't operate the commandline mindlessly"?
- wruza 4y agoAlso mv, ln.
- ciupicri 4y agoIt's been the default on Fedora and RHEL for many, many years.