nixers
rm -i - Printable Version
+- nixers (https://nixers.net)
+-- Forum: Operating Systems & Administration (https://nixers.net/Forum-Operating-Systems-Administration)
+--- Forum: BSD (https://nixers.net/Forum-BSD)
+--- Thread: rm -i (/Thread-rm-i)


rm -i - pfr - 21-11-2021

Possibly a stupid question:

I have 'rm' aliased to 'rm -i' which is not uncommon. However, I get frustrated when deleting large directories with 'rm -r' as the command 'rm -i -r' will ask me for confirmation to delete every single file within the directory.

Is there any way around this? Ideally I'd like it to ask me to confirm when deleting single files but when multiple files are being deleted I'd love for it to just ask me once to confirm deleting recursively.

Any way of achieving this?


RE: rm -i - venam - 21-11-2021

When I want to override and alias, I prepend it with "command". So maybe you could try: `command rm -r`.


RE: rm -i - pfr - 21-11-2021

(21-11-2021, 08:18 AM)venam Wrote: prepend it with "command"
Perfect. Thank you!

edit: better still, I'll just create another alias rmr="rm -r" and use that on directories instead.


RE: rm -i - mattrose - 21-11-2021

This is actually a standard alias for root on some old Redhat based distros, so whenever I hit that problem, I usually just override it with `-f` so `rm -rf directory`


RE: rm -i - seninha - 21-11-2021

I (with the help of the #bash IRC channel) created this function that simulates GNU rm -I (the less-intrusive interactive functionality that GNU rm has). Just put it in your ~/.kshrc: https://0x0.st/-7Xb.sh

Edit: What that function actually does is: it prompts for confirmation for each file, as usual. But only if you give as argument three or less files and, if calling it recursively (-r), only non-directory files were given.
If you give as argument more then one files or (with the -r option) a directory, it asks for confirmation only once for all files (instead of prompting for each file).


RE: rm -i - movq - 21-11-2021

(21-11-2021, 08:18 AM)venam Wrote: When I want to override and alias, I prepend it with "command". So maybe you could try: `command rm -r`.

There’s also the super intuitive and totally obvious version of prefixing the command with a backslash, so `\rm -r` would invoke the original `rm`. I haven’t checked how portable that is, but it at least works on Bash and OpenBSD’s ksh.


RE: rm -i - z3bra - 21-11-2021

As said above, you can simply "rm -rf directory" as it will expand to "rm -i -rf directory" and -f takes precedence over -i.


RE: rm -i - pfr - 26-11-2021

(21-11-2021, 12:48 PM)seninha Wrote: I (with the help of the #bash IRC channel) created this function that simulates GNU rm -I (the less-intrusive interactive functionality that GNU rm has). Just put it in your ~/.kshrc: https://0x0.st/-7Xb.sh

Neat! In my case, my ~/.shrc is already quite lengthy with lots (I mean LOTS) or aliases and functions. Why not add more :)

(21-11-2021, 03:55 PM)z3bra Wrote: As said above, you can simply "rm -rf directory" as it will expand to "rm -i -rf directory" and -f takes precedence over -i.

This is the simplest solution, but I was looking for a soution that meant I could just type rm and it will intuitively either use -i or -rf. Yes, I am that lazy that I only want to type 2 letters!


RE: rm -i - maksim - 05-10-2022

This might sound weird, but have you tried aliasing rm -r to rm -r ? If you put it below the rm alias, it should overwrite its' behavior.