The function given in @Tim's answer will work on any system running bash. However, GNU rm
already has an option for what you need (from man rm
):
-I prompt once before removing more than three
files, or when removing recursively. Less
intrusive than -i, while still giving protec‐
tion against most mistakes
So, if you have GNU rm
(which you should if you're running Linux) all you need is to add this line to your /.bashrc
:
alias rm='rm -I'
This will prompt before deleting more than 3 files, but it will not ask for confirmation for every file, if you confirm the action, all files will be deleted.
[$#
instead of[ $#
(missing space). Also this code is designed for use in a script or in a function. – Gilles 'SO- stop being evil' Sep 23 '13 at 21:12.bashrc
, you should make it into a function. Try wrapping this exact code inrm () { ... }
. – Joseph R. Sep 23 '13 at 21:15if [ $# -ge 3 ]; then (rm -i "${@}") else (rm "${@}") fi
\Whats wrong here? without the curly braces it still gives an error – user2805361 Sep 23 '13 at 21:18if [ $# -ge 3 ]; then 'rm -i' "$@" \ else 'rm' "$@" fi
i added that backslash and terminal didnd give error but still when deleting it dosent prompt – user2805361 Sep 23 '13 at 21:31