I want rm
to prompt me when recursively deleting a directory, as in:
$ rm -r <dir>
Do you want to remove the dir(Y/N)?
Is there an argument I can pass to rm
that will do this?
What you want is uppercase -I
, as in:
$ rm -rI tg/
rm: remove all arguments recursively?
As noted in the comments, this is something nice GNU's rm
is giving you, and not required based on the posix spec for rm
.
rm
; is it GNU? Mac? ...?)
Commented
Oct 28, 2014 at 21:40
rmdir
is sort of OK because on another system it would just refuse to remove anything at all.
Commented
Oct 30, 2014 at 17:59
Depending on what OS you're on, there's rm -i
(which will prompt for each individual file) or perhaps rm -I
(part of GNU rm), which, per the man page, will "prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while still giving protection against most mistakes"
I highly recommend against creating an alias for this, and instead build the habit of using one or the other of the above options. Being on a system without the alias you've gotten used to can create much grief (removing files you didn't intend to remove). Using the habitual option when you actually don't want it just means a minor annoyance (being prompted a few times, and either answering yes to each prompt, or breaking out (C-c) and starting again without the option). The latter is much less painful, I find.
-i
, he specifically asked for a single prompt. Also you'll notice the question was updated a while ago to remove everything about aliases
Commented
Oct 30, 2014 at 18:05
rm -I
, so that's why I included it in my answer. I see you've updated you answer to remove the aliasing (I guess thanks to my comment; maybe I should have left it at that; I never saw it in the question), so this answer becomes a bit redundant now. Perhaps I'll withdraw it; certainly, I'll now upvote your answer, now that it doesn't suggest using an alias.
Commented
Oct 30, 2014 at 23:19
rm -i
commandrm
torm -rf
, so that it gets easier to remove a directory" -- right, becauserm -f
isn't quite dangerous enough.