rm -i - BSD

Users browsing this thread: 2 Guest(s)
 pfr Offline | 21-11-2021, 08:16 AM | #1
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?
_____________________________________________________________________________________________
“Maybe you have some bird ideas... Maybe that's the best you can do.” - Terry A. Davis (R.I.P Terry & Percival)
 venam Offline | 21-11-2021, 08:18 AM | #2
When I want to override and alias, I prepend it with "command". So maybe you could try: command rm -r.
 pfr Offline | 21-11-2021, 08:31 AM | #3
(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.
 mattrose Offline | 21-11-2021, 10:48 AM | #4
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
 seninha Offline | 21-11-2021, 12:48 PM | #5
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).
 movq Offline | 21-11-2021, 02:34 PM | #6
(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.
 z3bra Offline | 21-11-2021, 03:55 PM | #7
As said above, you can simply "rm -rf directory" as it will expand to "rm -i -rf directory" and -f takes precedence over -i.
 pfr Offline | 26-11-2021, 01:27 AM | #8
(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!