2

I'd like to do this, on OSX:

alias rm="rm -I"

In GNU rm, this means that rm will prompt if it's recursive or if it's deleting three or more files, but not if it's just deleting one or two files. However, OSX (Mavericks) rm doesn't support this.

Is there a workaround so that rm will prompt, once, when deleting several files, but won't prompt for single files, or for every single file in mass deletes?

1 Answers1

0

The linked answer gave me a good start, but was a bit simplistic - it triggered if you had a glob matching 3 files, but not if you were doing rm -rf foo.

So this works for me in ~.bash_profile:

rmf() {
    if [ "$1" == "-rf" ]; then
        read -r -p "Sure you want to delete '${2}' [y/N]? " response
        if [[ $response =~ ^(yes|y| ) ]]; then
            command rm "$@"
        fi
    else
        command rm "$@"
    fi
}
alias rm=rmf